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 --- cache.c | 2 +- cgit.c | 26 +++++++++++++------------- configfile.c | 6 +++--- html.c | 6 +++--- parsing.c | 6 +++--- shared.c | 12 ++++++------ ui-atom.c | 2 +- ui-diff.c | 5 +++-- ui-log.c | 6 +++--- ui-repolist.c | 14 +++++++------- ui-shared.c | 18 +++++++++--------- ui-snapshot.c | 2 +- ui-stats.c | 17 ++++++++++------- ui-tag.c | 2 +- 14 files changed, 64 insertions(+), 60 deletions(-) diff --git a/cache.c b/cache.c index 47cdcb4..3127fc2 100644 --- a/cache.c +++ b/cache.c @@ -363,7 +363,7 @@ int cache_process(int size, const char *path, const char *key, int ttl, /* Return a strftime formatted date/time * NB: the result from this function is to shared memory */ -char *sprintftime(const char *format, time_t time) +static char *sprintftime(const char *format, time_t time) { static char buf[64]; struct tm *tm; 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; diff --git a/configfile.c b/configfile.c index 3fa217f..d98989c 100644 --- a/configfile.c +++ b/configfile.c @@ -10,7 +10,7 @@ #include #include "configfile.h" -int next_char(FILE *f) +static int next_char(FILE *f) { int c = fgetc(f); if (c == '\r') { @@ -23,7 +23,7 @@ int next_char(FILE *f) return c; } -void skip_line(FILE *f) +static void skip_line(FILE *f) { int c; @@ -31,7 +31,7 @@ void skip_line(FILE *f) ; } -int read_config_line(FILE *f, char *line, const char **value, int bufsize) +static int read_config_line(FILE *f, char *line, const char **value, int bufsize) { int i = 0, isname = 0; diff --git a/html.c b/html.c index 90cc1c0..b5c6903 100644 --- a/html.c +++ b/html.c @@ -39,7 +39,7 @@ static const char* url_escape_table[256] = { "%fe", "%ff" }; -int htmlfd = STDOUT_FILENO; +static int htmlfd = STDOUT_FILENO; char *fmt(const char *format, ...) { @@ -266,7 +266,7 @@ int html_include(const char *filename) return 0; } -int hextoint(char c) +static int hextoint(char c) { if (c >= 'a' && c <= 'f') return 10 + c - 'a'; @@ -278,7 +278,7 @@ int hextoint(char c) return -1; } -char *convert_query_hexchar(char *txt) +static char *convert_query_hexchar(char *txt) { int d1, d2, n; n = strlen(txt); diff --git a/parsing.c b/parsing.c index 9b7efb3..658621d 100644 --- a/parsing.c +++ b/parsing.c @@ -52,7 +52,7 @@ void cgit_parse_url(const char *url) } } -char *substr(const char *head, const char *tail) +static char *substr(const char *head, const char *tail) { char *buf; @@ -64,7 +64,7 @@ char *substr(const char *head, const char *tail) return buf; } -char *parse_user(char *t, char **name, char **email, unsigned long *date) +static char *parse_user(char *t, char **name, char **email, unsigned long *date) { char *p = t; int mode = 1; @@ -101,7 +101,7 @@ char *parse_user(char *t, char **name, char **email, unsigned long *date) #ifdef NO_ICONV #define reencode(a, b, c) #else -const char *reencode(char **txt, const char *src_enc, const char *dst_enc) +static const char *reencode(char **txt, const char *src_enc, const char *dst_enc) { char *tmp; 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; diff --git a/ui-atom.c b/ui-atom.c index b218456..5b5525d 100644 --- a/ui-atom.c +++ b/ui-atom.c @@ -10,7 +10,7 @@ #include "html.h" #include "ui-shared.h" -void add_entry(struct commit *commit, char *host) +static void add_entry(struct commit *commit, char *host) { char delim = '&'; char *hex; diff --git a/ui-diff.c b/ui-diff.c index 49e5b46..7de7802 100644 --- a/ui-diff.c +++ b/ui-diff.c @@ -166,8 +166,9 @@ static void inspect_filepair(struct diff_filepair *pair) total_rems += lines_removed; } -void cgit_print_diffstat(const unsigned char *old_sha1, - const unsigned char *new_sha1, const char *prefix) +static void cgit_print_diffstat(const unsigned char *old_sha1, + const unsigned char *new_sha1, + const char *prefix) { int i; diff --git a/ui-log.c b/ui-log.c index 2f41602..857c05c 100644 --- a/ui-log.c +++ b/ui-log.c @@ -28,7 +28,7 @@ static const char *column_colors_html[] = { #define COLUMN_COLORS_HTML_MAX (ARRAY_SIZE(column_colors_html) - 1) -void count_lines(char *line, int size) +static void count_lines(char *line, int size) { if (size <= 0) return; @@ -40,7 +40,7 @@ void count_lines(char *line, int size) rem_lines++; } -void inspect_files(struct diff_filepair *pair) +static void inspect_files(struct diff_filepair *pair) { unsigned long old_size = 0; unsigned long new_size = 0; @@ -95,7 +95,7 @@ next: } } -void print_commit(struct commit *commit, struct rev_info *revs) +static void print_commit(struct commit *commit, struct rev_info *revs) { struct commitinfo *info; int cols = revs->graph ? 3 : 2; diff --git a/ui-repolist.c b/ui-repolist.c index 1ae22aa..66c88c4 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -12,7 +12,7 @@ #include "ui-shared.h" #include -time_t read_agefile(char *path) +static time_t read_agefile(char *path) { time_t result; size_t size; @@ -76,7 +76,7 @@ static void print_modtime(struct cgit_repo *repo) cgit_print_age(t, -1, NULL); } -int is_match(struct cgit_repo *repo) +static int is_match(struct cgit_repo *repo) { if (!ctx.qry.search) return 1; @@ -91,7 +91,7 @@ int is_match(struct cgit_repo *repo) return 0; } -int is_in_url(struct cgit_repo *repo) +static int is_in_url(struct cgit_repo *repo) { if (!ctx.qry.url) return 1; @@ -100,7 +100,7 @@ int is_in_url(struct cgit_repo *repo) return 0; } -void print_sort_header(const char *title, const char *sort) +static void print_sort_header(const char *title, const char *sort) { htmlf("%s", title); } -void print_header() +static void print_header() { html(""); print_sort_header("Name", "name"); @@ -124,7 +124,7 @@ void print_header() } -void print_pager(int items, int pagelen, char *search, char *sort) +static void print_pager(int items, int pagelen, char *search, char *sort) { int i, ofs; char *class = NULL; @@ -223,7 +223,7 @@ struct sortcolumn sortcolumn[] = { {NULL, NULL} }; -int sort_repolist(char *field) +static int sort_repolist(char *field) { struct sortcolumn *column; diff --git a/ui-shared.c b/ui-shared.c index af5310b..63a7116 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -121,7 +121,7 @@ const char *cgit_repobasename(const char *reponame) return rvbuf; } -char *cgit_currurl() +static char *cgit_currurl() { if (!ctx.cfg.virtual_root) return ctx.cfg.script_name; @@ -433,8 +433,8 @@ void cgit_stats_link(const char *name, const char *title, const char *class, reporevlink("stats", name, title, class, head, NULL, path); } -void cgit_self_link(char *name, const char *title, const char *class, - struct cgit_context *ctx) +static void cgit_self_link(char *name, const char *title, const char *class, + struct cgit_context *ctx) { if (!strcmp(ctx->qry.page, "repolist")) return cgit_index_link(name, title, class, ctx->qry.search, ctx->qry.sort, @@ -512,8 +512,8 @@ void cgit_object_link(struct object *obj) reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); } -struct string_list_item *lookup_path(struct string_list *list, - const char *path) +static struct string_list_item *lookup_path(struct string_list *list, + const char *path) { struct string_list_item *item; @@ -716,16 +716,16 @@ void cgit_print_docend() html("\n\n"); } -int print_branch_option(const char *refname, const unsigned char *sha1, - int flags, void *cb_data) +static int print_branch_option(const char *refname, const unsigned char *sha1, + int flags, void *cb_data) { char *name = (char *)refname; html_option(name, name, ctx.qry.head); return 0; } -int print_archive_ref(const char *refname, const unsigned char *sha1, - int flags, void *cb_data) +static int print_archive_ref(const char *refname, const unsigned char *sha1, + int flags, void *cb_data) { struct tag *tag; struct taginfo *info; diff --git a/ui-snapshot.c b/ui-snapshot.c index 54e659c..e199a92 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c @@ -153,7 +153,7 @@ static const char *get_ref_from_filename(const char *url, const char *filename, return NULL; } -void show_error(char *msg) +static void show_error(char *msg) { ctx.page.mimetype = "text/html"; cgit_print_http_headers(&ctx); diff --git a/ui-stats.c b/ui-stats.c index 9cf1dbd..480c8ee 100644 --- a/ui-stats.c +++ b/ui-stats.c @@ -211,8 +211,8 @@ static int cmp_total_commits(const void *a1, const void *a2) /* Walk the commit DAG and collect number of commits per author per * timeperiod into a nested string_list collection. */ -struct string_list collect_stats(struct cgit_context *ctx, - struct cgit_period *period) +static struct string_list collect_stats(struct cgit_context *ctx, + struct cgit_period *period) { struct string_list authors; struct rev_info rev; @@ -253,9 +253,12 @@ struct string_list collect_stats(struct cgit_context *ctx, return authors; } -void print_combined_authorrow(struct string_list *authors, int from, int to, - const char *name, const char *leftclass, const char *centerclass, - const char *rightclass, struct cgit_period *period) +static void print_combined_authorrow(struct string_list *authors, int from, + int to, const char *name, + const char *leftclass, + const char *centerclass, + const char *rightclass, + struct cgit_period *period) { struct string_list_item *author; struct authorstat *authorstat; @@ -293,8 +296,8 @@ void print_combined_authorrow(struct string_list *authors, int from, int to, htmlf("%ld", rightclass, total); } -void print_authors(struct string_list *authors, int top, - struct cgit_period *period) +static void print_authors(struct string_list *authors, int top, + struct cgit_period *period) { struct string_list_item *author; struct authorstat *authorstat; diff --git a/ui-tag.c b/ui-tag.c index cab96b1..4d340d4 100644 --- a/ui-tag.c +++ b/ui-tag.c @@ -30,7 +30,7 @@ static void print_tag_content(char *buf) } } -void print_download_links(char *revname) +static void print_download_links(char *revname) { html("download"); cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, -- cgit v1.2.3-18-g5258 From 71926bfb342b75a6721441b1fe9b9db8b50775d5 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 08:52:34 +0100 Subject: ui-shared.c: Remove unused function cgit_currurl() This is no longer used as of commit 0c8e184e. Signed-off-by: Lukas Fleischer --- ui-shared.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 63a7116..31224bc 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -121,18 +121,6 @@ const char *cgit_repobasename(const char *reponame) return rvbuf; } -static char *cgit_currurl() -{ - if (!ctx.cfg.virtual_root) - return ctx.cfg.script_name; - else if (ctx.qry.page) - return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page); - else if (ctx.qry.repo) - return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo); - else - return fmt("%s/", ctx.cfg.virtual_root); -} - static void site_url(const char *page, const char *search, const char *sort, int ofs) { char *delim = "?"; -- cgit v1.2.3-18-g5258 From 1a5e8633ce3ec7f3a82bc0f4ca5ca810473714b9 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 08:52:35 +0100 Subject: ui-shared.c: Remove unused function print_archive_ref() This is no longer used as of commit f135569b. Signed-off-by: Lukas Fleischer --- ui-shared.c | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/ui-shared.c b/ui-shared.c index 31224bc..77a302d 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -712,45 +712,6 @@ static int print_branch_option(const char *refname, const unsigned char *sha1, return 0; } -static int print_archive_ref(const char *refname, const unsigned char *sha1, - int flags, void *cb_data) -{ - struct tag *tag; - struct taginfo *info; - struct object *obj; - char buf[256], *url; - unsigned char fileid[20]; - int *header = (int *)cb_data; - - if (prefixcmp(refname, "refs/archives")) - return 0; - strncpy(buf, refname + 14, sizeof(buf)); - obj = parse_object(sha1); - if (!obj) - return 1; - if (obj->type == OBJ_TAG) { - tag = lookup_tag(sha1); - if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) - return 0; - hashcpy(fileid, tag->tagged->sha1); - } else if (obj->type != OBJ_BLOB) { - return 0; - } else { - hashcpy(fileid, sha1); - } - if (!*header) { - html("

download

\n"); - *header = 1; - } - url = cgit_pageurl(ctx.qry.repo, "blob", - fmt("id=%s&path=%s", sha1_to_hex(fileid), - buf)); - html_link_open(url, NULL, "menu"); - html_txt(strlpart(buf, 20)); - html_link_close(); - return 0; -} - void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page) { -- cgit v1.2.3-18-g5258 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 --- cgit.h | 1 + shared.c | 36 ++++++++++++++++++++++++++++++++++++ ui-refs.c | 4 ++++ 3 files changed, 41 insertions(+) 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); extern char *strrpart(char *txt, int maxlen); extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); +extern void cgit_free_reflist_inner(struct reflist *list); extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, void *cb_data); 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) { 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) if (maxcount < list.count) print_refs_link("heads"); + + cgit_free_reflist_inner(&list); } void cgit_print_tags(int maxcount) @@ -229,6 +231,8 @@ void cgit_print_tags(int maxcount) if (maxcount < list.count) print_refs_link("tags"); + + cgit_free_reflist_inner(&list); } void cgit_print_refs() -- cgit v1.2.3-18-g5258 From fab385ef5ca516dcda79df87eb926eccdda64a54 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 13:25:34 +0100 Subject: print_tag_downloads(): Free ref variable Make sure the ref variable is freed if we build a "$basename-$version"-style ref. This fixes following memory leak seen with "PATH_INFO=/cgit/refs/": ==8784== 323 bytes in 29 blocks are definitely lost in loss record 41 of 53 ==8784== at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==8784== by 0x56F2DF1: strdup (in /usr/lib/libc-2.17.so) ==8784== by 0x46CA28: xstrdup (wrapper.c:35) ==8784== by 0x410DA6: print_tag_downloads (ui-refs.c:115) ==8784== by 0x410F02: print_tag (ui-refs.c:141) ==8784== by 0x41128B: cgit_print_tags (ui-refs.c:230) ==8784== by 0x41134D: cgit_print_refs (ui-refs.c:250) ==8784== by 0x407C85: refs_fn (cmd.c:105) ==8784== by 0x405DDF: process_request (cgit.c:566) ==8784== by 0x407490: cache_process (cache.c:322) ==8784== by 0x406C18: main (cgit.c:864) Signed-off-by: Lukas Fleischer --- ui-refs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ui-refs.c b/ui-refs.c index 4a9b8d3..e89f836 100644 --- a/ui-refs.c +++ b/ui-refs.c @@ -103,6 +103,7 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) const struct cgit_snapshot_format* f; char *filename; const char *basename; + int free_ref = 0; if (!ref || strlen(ref) < 2) return; @@ -111,8 +112,10 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) if (prefixcmp(ref, basename) != 0) { if ((ref[0] == 'v' || ref[0] == 'V') && isdigit(ref[1])) ref++; - if (isdigit(ref[0])) + if (isdigit(ref[0])) { ref = xstrdup(fmt("%s-%s", basename, ref)); + free_ref = 1; + } } for (f = cgit_snapshot_formats; f->suffix; f++) { @@ -122,6 +125,9 @@ static void print_tag_downloads(const struct cgit_repo *repo, const char *ref) cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); html("  "); } + + if (free_ref) + free((char *)ref); } static int print_tag(struct refinfo *ref) { -- cgit v1.2.3-18-g5258 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(+) 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-18-g5258 From 985d6ca7e70ca4774b81106e9eeecd619e5b3930 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 13:25:36 +0100 Subject: cgit_print_tree(): Free curr_rev after usage Fixes following memory leak seen with "PATH_INFO=/cgit/tree/": ==15715== 7 bytes in 1 blocks are definitely lost in loss record 4 of 51 ==15715== at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==15715== by 0x56F2DF1: strdup (in /usr/lib/libc-2.17.so) ==15715== by 0x46CAA8: xstrdup (wrapper.c:35) ==15715== by 0x418A4C: cgit_print_tree (ui-tree.c:274) ==15715== by 0x407D91: tree_fn (cmd.c:131) ==15715== by 0x405E16: process_request (cgit.c:574) ==15715== by 0x4074C8: cache_process (cache.c:322) ==15715== by 0x406C4F: main (cgit.c:872) Signed-off-by: Lukas Fleischer --- ui-tree.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ui-tree.c b/ui-tree.c index 561f9e7..b692b56 100644 --- a/ui-tree.c +++ b/ui-tree.c @@ -271,7 +271,6 @@ void cgit_print_tree(const char *rev, char *path) if (!rev) rev = ctx.qry.head; - walk_tree_ctx.curr_rev = xstrdup(rev); if (get_sha1(rev, sha1)) { cgit_print_error(fmt("Invalid revision name: %s", rev)); return; @@ -282,12 +281,17 @@ void cgit_print_tree(const char *rev, char *path) return; } + walk_tree_ctx.curr_rev = xstrdup(rev); + if (path == NULL) { ls_tree(commit->tree->object.sha1, NULL, &walk_tree_ctx); - return; + goto cleanup; } read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx); if (walk_tree_ctx.state == 1) ls_tail(); + +cleanup: + free(walk_tree_ctx.curr_rev); } -- cgit v1.2.3-18-g5258 From bc2f5a6d53fa8ec1dee3335dd6de4650f834231b Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 13:25:37 +0100 Subject: cgit_print_commit(): Free tmp variable Fixes following memory leak seen with "PATH_INFO=/cgit/commit/": ==16894== 7 bytes in 1 blocks are definitely lost in loss record 4 of 92 ==16894== at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==16894== by 0x56F2DF1: strdup (in /usr/lib/libc-2.17.so) ==16894== by 0x46CAC8: xstrdup (wrapper.c:35) ==16894== by 0x40CD6F: cgit_print_commit (ui-commit.c:70) ==16894== by 0x407B06: commit_fn (cmd.c:54) ==16894== by 0x405E16: process_request (cgit.c:574) ==16894== by 0x4074C8: cache_process (cache.c:322) ==16894== by 0x406C4F: main (cgit.c:872) Signed-off-by: Lukas Fleischer --- ui-commit.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-commit.c b/ui-commit.c index 74f37c8..0783285 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -74,6 +74,7 @@ void cgit_print_commit(char *hex, const char *prefix) html(" /"); cgit_tree_link(prefix, NULL, NULL, ctx.qry.head, tmp, prefix); } + free(tmp); html("\n"); for (p = commit->parents; p; p = p->next) { parent = lookup_commit_reference(p->item->object.sha1); -- cgit v1.2.3-18-g5258 From 59fe348deaa270434f05afc56ca8d13618af9ca9 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 4 Mar 2013 13:25:38 +0100 Subject: cgit_print_snapshot_links(): Free prefix variable Fixes following memory leak seen with "PATH_INFO=/cgit/commit/": ==16894== 12 bytes in 1 blocks are definitely lost in loss record 9 of 92 ==16894== at 0x4C2C04B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==16894== by 0x56F2DF1: strdup (in /usr/lib/libc-2.17.so) ==16894== by 0x46CAC8: xstrdup (wrapper.c:35) ==16894== by 0x414E34: cgit_print_snapshot_links (ui-shared.c:926) ==16894== by 0x40CFA1: cgit_print_commit (ui-commit.c:102) ==16894== by 0x407B06: commit_fn (cmd.c:54) ==16894== by 0x405E16: process_request (cgit.c:574) ==16894== by 0x4074C8: cache_process (cache.c:322) ==16894== by 0x406C4F: main (cgit.c:872) Signed-off-by: Lukas Fleischer --- ui-shared.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-shared.c b/ui-shared.c index 77a302d..d3e6488 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -931,4 +931,5 @@ void cgit_print_snapshot_links(const char *repo, const char *head, cgit_snapshot_link(filename, NULL, NULL, NULL, NULL, filename); html("
"); } + free(prefix); } -- cgit v1.2.3-18-g5258