From bafab423f20bc1448b293842c235965e1681f07e Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 08:52:33 +0100 Subject: Mark several functions/variables static Spotted by parsing the output of `gcc -Wmissing-prototypes [...]`. Signed-off-by: Lukas Fleischer --- shared.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'shared.c') diff --git a/shared.c b/shared.c index e732064..124d079 100644 --- a/shared.c +++ b/shared.c @@ -158,7 +158,7 @@ void cgit_add_ref(struct reflist *list, struct refinfo *ref) list->refs[list->count++] = ref; } -struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) +static struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) { struct refinfo *ref; @@ -187,8 +187,8 @@ int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, return 0; } -void cgit_diff_tree_cb(struct diff_queue_struct *q, - struct diff_options *options, void *data) +static void cgit_diff_tree_cb(struct diff_queue_struct *q, + struct diff_options *options, void *data) { int i; @@ -224,7 +224,7 @@ static int load_mmfile(mmfile_t *file, const unsigned char *sha1) char *diffbuf = NULL; int buflen = 0; -int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) +static int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) { int i; @@ -461,14 +461,14 @@ int readfile(const char *path, char **buf, size_t *size) return (*size == st.st_size ? 0 : e); } -int is_token_char(char c) +static int is_token_char(char c) { return isalnum(c) || c == '_'; } /* Replace name with getenv(name), return pointer to zero-terminating char */ -char *expand_macro(char *name, int maxlength) +static char *expand_macro(char *name, int maxlength) { char *value; int len; -- cgit v1.2.3 From 1268afe83692cb8a9ea839ab979d82458da2d03d Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 13:25:33 +0100 Subject: 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 --- shared.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'shared.c') 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 return ref; } +static void cgit_free_taginfo(struct taginfo *tag) +{ + if (tag->tagger) + free(tag->tagger); + if (tag->tagger_email) + free(tag->tagger_email); + if (tag->msg) + free(tag->msg); + free(tag); +} + +static void cgit_free_refinfo(struct refinfo *ref) +{ + if (ref->refname) + free((char *)ref->refname); + switch (ref->object->type) { + case OBJ_TAG: + cgit_free_taginfo(ref->tag); + break; + case OBJ_COMMIT: + cgit_free_commitinfo(ref->commit); + break; + } + free(ref); +} + +void cgit_free_reflist_inner(struct reflist *list) +{ + int i; + + for (i = 0; i < list->count; i++) { + cgit_free_refinfo(list->refs[i]); + } + free(list->refs); +} + int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { -- cgit v1.2.3