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 --- cgit.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index 2ccf864..5b20de3 100644 --- a/cgit.c +++ b/cgit.c @@ -18,7 +18,7 @@ const char *cgit_version = CGIT_VERSION; -void add_mimetype(const char *name, const char *value) +static void add_mimetype(const char *name, const char *value) { struct string_list_item *item; @@ -26,7 +26,7 @@ void add_mimetype(const char *name, const char *value) item->util = xstrdup(value); } -struct cgit_filter *new_filter(const char *cmd, filter_type filtertype) +static struct cgit_filter *new_filter(const char *cmd, filter_type filtertype) { struct cgit_filter *f; int args_size = 0; @@ -58,7 +58,7 @@ struct cgit_filter *new_filter(const char *cmd, filter_type filtertype) static void process_cached_repolist(const char *path); -void repo_config(struct cgit_repo *repo, const char *name, const char *value) +static void repo_config(struct cgit_repo *repo, const char *name, const char *value) { struct string_list_item *item; @@ -114,7 +114,7 @@ void repo_config(struct cgit_repo *repo, const char *name, const char *value) } } -void config_cb(const char *name, const char *value) +static void config_cb(const char *name, const char *value) { if (!strcmp(name, "section") || !strcmp(name, "repo.group")) ctx.cfg.section = xstrdup(value); @@ -333,7 +333,7 @@ static void querystring_cb(const char *name, const char *value) } } -char *xstrdupn(const char *str) +static char *xstrdupn(const char *str) { return (str ? xstrdup(str) : NULL); } @@ -414,8 +414,8 @@ struct refmatch { int match; }; -int find_current_ref(const char *refname, const unsigned char *sha1, - int flags, void *cb_data) +static int find_current_ref(const char *refname, const unsigned char *sha1, + int flags, void *cb_data) { struct refmatch *info; @@ -427,7 +427,7 @@ int find_current_ref(const char *refname, const unsigned char *sha1, return info->match; } -char *find_default_branch(struct cgit_repo *repo) +static char *find_default_branch(struct cgit_repo *repo) { struct refmatch info; char *ref; @@ -569,13 +569,13 @@ static void process_request(void *cbdata) cgit_print_docend(); } -int cmp_repos(const void *a, const void *b) +static int cmp_repos(const void *a, const void *b) { const struct cgit_repo *ra = a, *rb = b; return strcmp(ra->url, rb->url); } -char *build_snapshot_setting(int bitmap) +static char *build_snapshot_setting(int bitmap) { const struct cgit_snapshot_format *f; char *result = xstrdup(""); @@ -595,7 +595,7 @@ char *build_snapshot_setting(int bitmap) return result; } -char *get_first_line(char *txt) +static char *get_first_line(char *txt) { char *t = xstrdup(txt); char *p = strchr(t, '\n'); @@ -604,7 +604,7 @@ char *get_first_line(char *txt) return t; } -void print_repo(FILE *f, struct cgit_repo *repo) +static void print_repo(FILE *f, struct cgit_repo *repo) { fprintf(f, "repo.url=%s\n", repo->url); fprintf(f, "repo.name=%s\n", repo->name); @@ -649,7 +649,7 @@ void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "\n"); } -void print_repolist(FILE *f, struct cgit_repolist *list, int start) +static void print_repolist(FILE *f, struct cgit_repolist *list, int start) { int i; -- cgit v1.2.3-54-g00ecf From 0ffdc46f0830d89e32204e1b30145b4c26727e6c Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 13:25:35 +0100 Subject: find_default_branch(): Free refmatch after usage Fixes following memory leak seen with "PATH_INFO=/cgit/refs/": ==13408== 7 bytes in 1 blocks are definitely lost in loss record 4 of 52 ==13408== at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==13408== by 0x56F2DF1: strdup (in /usr/lib/libc-2.17.so) ==13408== by 0x46CA78: xstrdup (wrapper.c:35) ==13408== by 0x405840: find_current_ref (cgit.c:426) ==13408== by 0x44BE5A: do_one_ref (refs.c:527) ==13408== by 0x44D3E0: do_for_each_ref_in_dir (refs.c:553) ==13408== by 0x44D85A: do_for_each_ref (refs.c:1298) ==13408== by 0x405889: find_default_branch (cgit.c:438) ==13408== by 0x405AC4: prepare_repo_cmd (cgit.c:490) ==13408== by 0x405D97: process_request (cgit.c:557) ==13408== by 0x407490: cache_process (cache.c:322) ==13408== by 0x406C18: main (cgit.c:864) Signed-off-by: Lukas Fleischer --- cgit.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index 5b20de3..afafcce 100644 --- a/cgit.c +++ b/cgit.c @@ -427,6 +427,12 @@ static int find_current_ref(const char *refname, const unsigned char *sha1, return info->match; } +static void free_refmatch_inner(struct refmatch *info) +{ + if (info->first_ref) + free(info->first_ref); +} + static char *find_default_branch(struct cgit_repo *repo) { struct refmatch info; @@ -442,6 +448,8 @@ static char *find_default_branch(struct cgit_repo *repo) ref = info.first_ref; if (ref) ref = xstrdup(ref); + free_refmatch_inner(&info); + return ref; } -- cgit v1.2.3-54-g00ecf