summaryrefslogtreecommitdiffabout
authorFerry Huberts <ferry.huberts@pelagic.nl>2011-03-09 07:16:58 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2011-03-26 14:13:35 (UTC)
commit3f1ebd3565afa33196dfc3e8584e04564987e33c (patch) (unidiff)
tree714a4426c035416af4b4cb47bb90aecd4b3851c6
parent4d2a303c3e198c91cb6635eb66fa6f0a6c0277cc (diff)
downloadcgit-3f1ebd3565afa33196dfc3e8584e04564987e33c.zip
cgit-3f1ebd3565afa33196dfc3e8584e04564987e33c.tar.gz
cgit-3f1ebd3565afa33196dfc3e8584e04564987e33c.tar.bz2
source_filter: fix a memory leak
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ui-tree.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/ui-tree.c b/ui-tree.c
index 0b1b531..442b6be 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,146 +1,148 @@
1/* ui-tree.c: functions for tree output 1/* ui-tree.c: functions for tree output
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include <ctype.h> 9#include <ctype.h>
10#include "cgit.h" 10#include "cgit.h"
11#include "html.h" 11#include "html.h"
12#include "ui-shared.h" 12#include "ui-shared.h"
13 13
14char *curr_rev; 14char *curr_rev;
15char *match_path; 15char *match_path;
16int header = 0; 16int header = 0;
17 17
18static void print_text_buffer(const char *name, char *buf, unsigned long size) 18static void print_text_buffer(const char *name, char *buf, unsigned long size)
19{ 19{
20 unsigned long lineno, idx; 20 unsigned long lineno, idx;
21 const char *numberfmt = 21 const char *numberfmt =
22 "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; 22 "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n";
23 23
24 html("<table summary='blob content' class='blob'>\n"); 24 html("<table summary='blob content' class='blob'>\n");
25 25
26 if (ctx.cfg.enable_tree_linenumbers) { 26 if (ctx.cfg.enable_tree_linenumbers) {
27 html("<tr><td class='linenumbers'><pre>"); 27 html("<tr><td class='linenumbers'><pre>");
28 idx = 0; 28 idx = 0;
29 lineno = 0; 29 lineno = 0;
30 30
31 if (size) { 31 if (size) {
32 htmlf(numberfmt, ++lineno); 32 htmlf(numberfmt, ++lineno);
33 while(idx < size - 1) { // skip absolute last newline 33 while(idx < size - 1) { // skip absolute last newline
34 if (buf[idx] == '\n') 34 if (buf[idx] == '\n')
35 htmlf(numberfmt, ++lineno); 35 htmlf(numberfmt, ++lineno);
36 idx++; 36 idx++;
37 } 37 }
38 } 38 }
39 html("</pre></td>\n"); 39 html("</pre></td>\n");
40 } 40 }
41 else { 41 else {
42 html("<tr>\n"); 42 html("<tr>\n");
43 } 43 }
44 44
45 if (ctx.repo->source_filter) { 45 if (ctx.repo->source_filter) {
46 html("<td class='lines'><pre><code>"); 46 html("<td class='lines'><pre><code>");
47 ctx.repo->source_filter->argv[1] = xstrdup(name); 47 ctx.repo->source_filter->argv[1] = xstrdup(name);
48 cgit_open_filter(ctx.repo->source_filter); 48 cgit_open_filter(ctx.repo->source_filter);
49 html_raw(buf, size); 49 html_raw(buf, size);
50 cgit_close_filter(ctx.repo->source_filter); 50 cgit_close_filter(ctx.repo->source_filter);
51 free(ctx.repo->source_filter->argv[1]);
52 ctx.repo->source_filter->argv[1] = NULL;
51 html("</code></pre></td></tr></table>\n"); 53 html("</code></pre></td></tr></table>\n");
52 return; 54 return;
53 } 55 }
54 56
55 html("<td class='lines'><pre><code>"); 57 html("<td class='lines'><pre><code>");
56 html_txt(buf); 58 html_txt(buf);
57 html("</code></pre></td></tr></table>\n"); 59 html("</code></pre></td></tr></table>\n");
58} 60}
59 61
60#define ROWLEN 32 62#define ROWLEN 32
61 63
62static void print_binary_buffer(char *buf, unsigned long size) 64static void print_binary_buffer(char *buf, unsigned long size)
63{ 65{
64 unsigned long ofs, idx; 66 unsigned long ofs, idx;
65 static char ascii[ROWLEN + 1]; 67 static char ascii[ROWLEN + 1];
66 68
67 html("<table summary='blob content' class='bin-blob'>\n"); 69 html("<table summary='blob content' class='bin-blob'>\n");
68 html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); 70 html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>");
69 for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { 71 for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) {
70 htmlf("<tr><td class='right'>%04lx</td><td class='hex'>", ofs); 72 htmlf("<tr><td class='right'>%04lx</td><td class='hex'>", ofs);
71 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) 73 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
72 htmlf("%*s%02x", 74 htmlf("%*s%02x",
73 idx == 16 ? 4 : 1, "", 75 idx == 16 ? 4 : 1, "",
74 buf[idx] & 0xff); 76 buf[idx] & 0xff);
75 html(" </td><td class='hex'>"); 77 html(" </td><td class='hex'>");
76 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) 78 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
77 ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; 79 ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.';
78 ascii[idx] = '\0'; 80 ascii[idx] = '\0';
79 html_txt(ascii); 81 html_txt(ascii);
80 html("</td></tr>\n"); 82 html("</td></tr>\n");
81 } 83 }
82 html("</table>\n"); 84 html("</table>\n");
83} 85}
84 86
85static void print_object(const unsigned char *sha1, char *path, const char *basename) 87static void print_object(const unsigned char *sha1, char *path, const char *basename)
86{ 88{
87 enum object_type type; 89 enum object_type type;
88 char *buf; 90 char *buf;
89 unsigned long size; 91 unsigned long size;
90 92
91 type = sha1_object_info(sha1, &size); 93 type = sha1_object_info(sha1, &size);
92 if (type == OBJ_BAD) { 94 if (type == OBJ_BAD) {
93 cgit_print_error(fmt("Bad object name: %s", 95 cgit_print_error(fmt("Bad object name: %s",
94 sha1_to_hex(sha1))); 96 sha1_to_hex(sha1)));
95 return; 97 return;
96 } 98 }
97 99
98 buf = read_sha1_file(sha1, &type, &size); 100 buf = read_sha1_file(sha1, &type, &size);
99 if (!buf) { 101 if (!buf) {
100 cgit_print_error(fmt("Error reading object %s", 102 cgit_print_error(fmt("Error reading object %s",
101 sha1_to_hex(sha1))); 103 sha1_to_hex(sha1)));
102 return; 104 return;
103 } 105 }
104 106
105 htmlf("blob: %s (", sha1_to_hex(sha1)); 107 htmlf("blob: %s (", sha1_to_hex(sha1));
106 cgit_plain_link("plain", NULL, NULL, ctx.qry.head, 108 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
107 curr_rev, path); 109 curr_rev, path);
108 html(")\n"); 110 html(")\n");
109 111
110 if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { 112 if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) {
111 htmlf("<div class='error'>blob size (%ldKB) exceeds display size limit (%dKB).</div>", 113 htmlf("<div class='error'>blob size (%ldKB) exceeds display size limit (%dKB).</div>",
112 size / 1024, ctx.cfg.max_blob_size); 114 size / 1024, ctx.cfg.max_blob_size);
113 return; 115 return;
114 } 116 }
115 117
116 if (buffer_is_binary(buf, size)) 118 if (buffer_is_binary(buf, size))
117 print_binary_buffer(buf, size); 119 print_binary_buffer(buf, size);
118 else 120 else
119 print_text_buffer(basename, buf, size); 121 print_text_buffer(basename, buf, size);
120} 122}
121 123
122 124
123static int ls_item(const unsigned char *sha1, const char *base, int baselen, 125static int ls_item(const unsigned char *sha1, const char *base, int baselen,
124 const char *pathname, unsigned int mode, int stage, 126 const char *pathname, unsigned int mode, int stage,
125 void *cbdata) 127 void *cbdata)
126{ 128{
127 char *name; 129 char *name;
128 char *fullpath; 130 char *fullpath;
129 char *class; 131 char *class;
130 enum object_type type; 132 enum object_type type;
131 unsigned long size = 0; 133 unsigned long size = 0;
132 134
133 name = xstrdup(pathname); 135 name = xstrdup(pathname);
134 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", 136 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "",
135 ctx.qry.path ? "/" : "", name); 137 ctx.qry.path ? "/" : "", name);
136 138
137 if (!S_ISGITLINK(mode)) { 139 if (!S_ISGITLINK(mode)) {
138 type = sha1_object_info(sha1, &size); 140 type = sha1_object_info(sha1, &size);
139 if (type == OBJ_BAD) { 141 if (type == OBJ_BAD) {
140 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 142 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
141 name, 143 name,
142 sha1_to_hex(sha1)); 144 sha1_to_hex(sha1));
143 return 0; 145 return 0;
144 } 146 }
145 } 147 }
146 148