diff options
author | Lukas Fleischer | 2013-03-04 13:25:33 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2013-03-04 19:55:12 -0500 |
commit | 1268afe83692cb8a9ea839ab979d82458da2d03d (patch) | |
tree | 6c70b3b3e37ec08a07a93e3f2fa56cfcc77e8178 | |
parent | ui-shared.c: Remove unused function print_archive_ref() (diff) | |
download | cgit-1268afe83692cb8a9ea839ab979d82458da2d03d.tar.gz cgit-1268afe83692cb8a9ea839ab979d82458da2d03d.zip |
Free reflists after usage
Free reflists in cgit_print_branches() and in cgit_print_tags() before returning reflist structures to the stack. This fixes following memory leaks seen with "PATH_INFO=/cgit/refs/": ==5710== 1,312 (32 direct, 1,280 indirect) bytes in 1 blocks are definitely lost in loss record 63 of 71 ==5710== at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5710== by 0x4C2C2FF: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5710== by 0x46CA9B: xrealloc (wrapper.c:100) ==5710== by 0x40AAA6: cgit_add_ref (shared.c:156) ==5710== by 0x40ABC4: cgit_refs_cb (shared.c:186) ==5710== by 0x44BCBA: do_one_ref (refs.c:527) ==5710== by 0x44D240: do_for_each_ref_in_dir (refs.c:553) ==5710== by 0x44D6BA: do_for_each_ref (refs.c:1298) ==5710== by 0x410FE2: cgit_print_branches (ui-refs.c:191) ==5710== by 0x4111E9: cgit_print_refs (ui-refs.c:244) ==5710== by 0x407C85: refs_fn (cmd.c:105) ==5710== by 0x405DDF: process_request (cgit.c:566) ==5710== ==5710== 6,846 (256 direct, 6,590 indirect) bytes in 1 blocks are definitely lost in loss record 68 of 71 ==5710== at 0x4C2C25E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5710== by 0x46CA9B: xrealloc (wrapper.c:100) ==5710== by 0x40AAA6: cgit_add_ref (shared.c:156) ==5710== by 0x40ABC4: cgit_refs_cb (shared.c:186) ==5710== by 0x44BCBA: do_one_ref (refs.c:527) ==5710== by 0x44D240: do_for_each_ref_in_dir (refs.c:553) ==5710== by 0x44D6EC: do_for_each_ref (refs.c:1288) ==5710== by 0x4110D5: cgit_print_tags (ui-refs.c:218) ==5710== by 0x4111FD: cgit_print_refs (ui-refs.c:246) ==5710== by 0x407C85: refs_fn (cmd.c:105) ==5710== by 0x405DDF: process_request (cgit.c:566) ==5710== by 0x407490: cache_process (cache.c:322) Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | shared.c | 36 | ||||
-rw-r--r-- | ui-refs.c | 4 |
3 files changed, 41 insertions, 0 deletions
diff --git a/cgit.h b/cgit.h index c655bd8..ed5cf14 100644 --- a/cgit.h +++ b/cgit.h | |||
@@ -304,6 +304,7 @@ extern char *strlpart(char *txt, int maxlen); | |||
304 | extern char *strrpart(char *txt, int maxlen); | 304 | extern char *strrpart(char *txt, int maxlen); |
305 | 305 | ||
306 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); | 306 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
307 | extern void cgit_free_reflist_inner(struct reflist *list); | ||
307 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, | 308 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
308 | int flags, void *cb_data); | 309 | int flags, void *cb_data); |
309 | 310 | ||
diff --git a/shared.c b/shared.c index 124d079..cc06930 100644 --- a/shared.c +++ b/shared.c | |||
@@ -176,6 +176,42 @@ static struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char | |||
176 | return ref; | 176 | return ref; |
177 | } | 177 | } |
178 | 178 | ||
179 | static void cgit_free_taginfo(struct taginfo *tag) | ||
180 | { | ||
181 | if (tag->tagger) | ||
182 | free(tag->tagger); | ||
183 | if (tag->tagger_email) | ||
184 | free(tag->tagger_email); | ||
185 | if (tag->msg) | ||
186 | free(tag->msg); | ||
187 | free(tag); | ||
188 | } | ||
189 | |||
190 | static void cgit_free_refinfo(struct refinfo *ref) | ||
191 | { | ||
192 | if (ref->refname) | ||
193 | free((char *)ref->refname); | ||
194 | switch (ref->object->type) { | ||
195 | case OBJ_TAG: | ||
196 | cgit_free_taginfo(ref->tag); | ||
197 | break; | ||
198 | case OBJ_COMMIT: | ||
199 | cgit_free_commitinfo(ref->commit); | ||
200 | break; | ||
201 | } | ||
202 | free(ref); | ||
203 | } | ||
204 | |||
205 | void cgit_free_reflist_inner(struct reflist *list) | ||
206 | { | ||
207 | int i; | ||
208 | |||
209 | for (i = 0; i < list->count; i++) { | ||
210 | cgit_free_refinfo(list->refs[i]); | ||
211 | } | ||
212 | free(list->refs); | ||
213 | } | ||
214 | |||
179 | int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, | 215 | int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, |
180 | void *cb_data) | 216 | void *cb_data) |
181 | { | 217 | { |
diff --git a/ui-refs.c b/ui-refs.c index ce06b08..4a9b8d3 100644 --- a/ui-refs.c +++ b/ui-refs.c | |||
@@ -205,6 +205,8 @@ void cgit_print_branches(int maxcount) | |||
205 | 205 | ||
206 | if (maxcount < list.count) | 206 | if (maxcount < list.count) |
207 | print_refs_link("heads"); | 207 | print_refs_link("heads"); |
208 | |||
209 | cgit_free_reflist_inner(&list); | ||
208 | } | 210 | } |
209 | 211 | ||
210 | void cgit_print_tags(int maxcount) | 212 | void cgit_print_tags(int maxcount) |
@@ -229,6 +231,8 @@ void cgit_print_tags(int maxcount) | |||
229 | 231 | ||
230 | if (maxcount < list.count) | 232 | if (maxcount < list.count) |
231 | print_refs_link("tags"); | 233 | print_refs_link("tags"); |
234 | |||
235 | cgit_free_reflist_inner(&list); | ||
232 | } | 236 | } |
233 | 237 | ||
234 | void cgit_print_refs() | 238 | void cgit_print_refs() |