mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
Merge branch 'jk/decoration-and-other-leak-fixes'
Leakfix. * jk/decoration-and-other-leak-fixes: daemon: free listen_addr before returning revision: clear decoration structs during release_revisions() decorate: add clear_decoration() function
This commit is contained in:
commit
2920971a7f
39
daemon.c
39
daemon.c
@ -1243,19 +1243,20 @@ static int serve(struct string_list *listen_addr, int listen_port,
|
||||
int cmd_main(int argc, const char **argv)
|
||||
{
|
||||
int listen_port = 0;
|
||||
struct string_list listen_addr = STRING_LIST_INIT_NODUP;
|
||||
struct string_list listen_addr = STRING_LIST_INIT_DUP;
|
||||
int serve_mode = 0, inetd_mode = 0;
|
||||
const char *pid_file = NULL, *user_name = NULL, *group_name = NULL;
|
||||
int detach = 0;
|
||||
struct credentials *cred = NULL;
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
const char *v;
|
||||
|
||||
if (skip_prefix(arg, "--listen=", &v)) {
|
||||
string_list_append(&listen_addr, xstrdup_tolower(v));
|
||||
string_list_append_nodup(&listen_addr, xstrdup_tolower(v));
|
||||
continue;
|
||||
}
|
||||
if (skip_prefix(arg, "--port=", &v)) {
|
||||
@ -1437,22 +1438,26 @@ int cmd_main(int argc, const char **argv)
|
||||
die_errno("failed to redirect stderr to /dev/null");
|
||||
}
|
||||
|
||||
if (inetd_mode || serve_mode)
|
||||
return execute();
|
||||
if (inetd_mode || serve_mode) {
|
||||
ret = execute();
|
||||
} else {
|
||||
if (detach) {
|
||||
if (daemonize())
|
||||
die("--detach not supported on this platform");
|
||||
}
|
||||
|
||||
if (detach) {
|
||||
if (daemonize())
|
||||
die("--detach not supported on this platform");
|
||||
if (pid_file)
|
||||
write_file(pid_file, "%"PRIuMAX, (uintmax_t) getpid());
|
||||
|
||||
/* prepare argv for serving-processes */
|
||||
strvec_push(&cld_argv, argv[0]); /* git-daemon */
|
||||
strvec_push(&cld_argv, "--serve");
|
||||
for (i = 1; i < argc; ++i)
|
||||
strvec_push(&cld_argv, argv[i]);
|
||||
|
||||
ret = serve(&listen_addr, listen_port, cred);
|
||||
}
|
||||
|
||||
if (pid_file)
|
||||
write_file(pid_file, "%"PRIuMAX, (uintmax_t) getpid());
|
||||
|
||||
/* prepare argv for serving-processes */
|
||||
strvec_push(&cld_argv, argv[0]); /* git-daemon */
|
||||
strvec_push(&cld_argv, "--serve");
|
||||
for (i = 1; i < argc; ++i)
|
||||
strvec_push(&cld_argv, argv[i]);
|
||||
|
||||
return serve(&listen_addr, listen_port, cred);
|
||||
string_list_clear(&listen_addr, 0);
|
||||
return ret;
|
||||
}
|
||||
|
15
decorate.c
15
decorate.c
@ -81,3 +81,18 @@ void *lookup_decoration(struct decoration *n, const struct object *obj)
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void clear_decoration(struct decoration *n, void (*free_cb)(void *))
|
||||
{
|
||||
if (free_cb) {
|
||||
unsigned int i;
|
||||
for (i = 0; i < n->size; i++) {
|
||||
void *d = n->entries[i].decoration;
|
||||
if (d)
|
||||
free_cb(d);
|
||||
}
|
||||
}
|
||||
|
||||
FREE_AND_NULL(n->entries);
|
||||
n->size = n->nr = 0;
|
||||
}
|
||||
|
10
decorate.h
10
decorate.h
@ -58,4 +58,14 @@ void *add_decoration(struct decoration *n, const struct object *obj, void *decor
|
||||
*/
|
||||
void *lookup_decoration(struct decoration *n, const struct object *obj);
|
||||
|
||||
/*
|
||||
* Clear all decoration entries, releasing any memory used by the structure.
|
||||
* If free_cb is not NULL, it is called for every decoration value currently
|
||||
* stored.
|
||||
*
|
||||
* After clearing, the decoration struct can be used again. The "name" field is
|
||||
* retained.
|
||||
*/
|
||||
void clear_decoration(struct decoration *n, void (*free_cb)(void *));
|
||||
|
||||
#endif
|
||||
|
10
line-log.c
10
line-log.c
@ -1327,3 +1327,13 @@ int line_log_filter(struct rev_info *rev)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void free_void_line_log_data(void *data)
|
||||
{
|
||||
free_line_log_data(data);
|
||||
}
|
||||
|
||||
void line_log_free(struct rev_info *rev)
|
||||
{
|
||||
clear_decoration(&rev->line_log_data, free_void_line_log_data);
|
||||
}
|
||||
|
@ -60,4 +60,6 @@ int line_log_process_ranges_arbitrary_commit(struct rev_info *rev,
|
||||
|
||||
int line_log_print(struct rev_info *rev, struct commit *commit);
|
||||
|
||||
void line_log_free(struct rev_info *rev);
|
||||
|
||||
#endif /* LINE_LOG_H */
|
||||
|
@ -3083,6 +3083,11 @@ static void release_revisions_mailmap(struct string_list *mailmap)
|
||||
|
||||
static void release_revisions_topo_walk_info(struct topo_walk_info *info);
|
||||
|
||||
static void free_void_commit_list(void *list)
|
||||
{
|
||||
free_commit_list(list);
|
||||
}
|
||||
|
||||
void release_revisions(struct rev_info *revs)
|
||||
{
|
||||
free_commit_list(revs->commits);
|
||||
@ -3100,6 +3105,10 @@ void release_revisions(struct rev_info *revs)
|
||||
diff_free(&revs->pruning);
|
||||
reflog_walk_info_release(revs->reflog_info);
|
||||
release_revisions_topo_walk_info(revs->topo_walk_info);
|
||||
clear_decoration(&revs->children, free_void_commit_list);
|
||||
clear_decoration(&revs->merge_simplification, free);
|
||||
clear_decoration(&revs->treesame, free);
|
||||
line_log_free(revs);
|
||||
}
|
||||
|
||||
static void add_child(struct rev_info *revs, struct commit *parent, struct commit *child)
|
||||
|
@ -72,5 +72,7 @@ int cmd__example_decorate(int argc UNUSED, const char **argv UNUSED)
|
||||
if (objects_noticed != 2)
|
||||
BUG("should have 2 objects");
|
||||
|
||||
clear_decoration(&n, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
test_description='git log with filter options limiting the output'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup test' '
|
||||
|
@ -1,6 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='test disabling of git-over-tcp in clone/fetch'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
. "$TEST_DIRECTORY/lib-proto-disable.sh"
|
||||
. "$TEST_DIRECTORY/lib-git-daemon.sh"
|
||||
|
@ -1,6 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='check that example code compiles and runs'
|
||||
|
||||
TEST_PASSES_SANITIZE_LEAK=true
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'decorate' '
|
||||
|
Loading…
Reference in New Issue
Block a user