Skip to content

Commit 2920971

Browse files
committed
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
2 parents 09dcbb4 + badf2fe commit 2920971

File tree

10 files changed

+74
-16
lines changed

10 files changed

+74
-16
lines changed

daemon.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,19 +1243,20 @@ static int serve(struct string_list *listen_addr, int listen_port,
12431243
int cmd_main(int argc, const char **argv)
12441244
{
12451245
int listen_port = 0;
1246-
struct string_list listen_addr = STRING_LIST_INIT_NODUP;
1246+
struct string_list listen_addr = STRING_LIST_INIT_DUP;
12471247
int serve_mode = 0, inetd_mode = 0;
12481248
const char *pid_file = NULL, *user_name = NULL, *group_name = NULL;
12491249
int detach = 0;
12501250
struct credentials *cred = NULL;
12511251
int i;
1252+
int ret;
12521253

12531254
for (i = 1; i < argc; i++) {
12541255
const char *arg = argv[i];
12551256
const char *v;
12561257

12571258
if (skip_prefix(arg, "--listen=", &v)) {
1258-
string_list_append(&listen_addr, xstrdup_tolower(v));
1259+
string_list_append_nodup(&listen_addr, xstrdup_tolower(v));
12591260
continue;
12601261
}
12611262
if (skip_prefix(arg, "--port=", &v)) {
@@ -1437,22 +1438,26 @@ int cmd_main(int argc, const char **argv)
14371438
die_errno("failed to redirect stderr to /dev/null");
14381439
}
14391440

1440-
if (inetd_mode || serve_mode)
1441-
return execute();
1441+
if (inetd_mode || serve_mode) {
1442+
ret = execute();
1443+
} else {
1444+
if (detach) {
1445+
if (daemonize())
1446+
die("--detach not supported on this platform");
1447+
}
14421448

1443-
if (detach) {
1444-
if (daemonize())
1445-
die("--detach not supported on this platform");
1446-
}
1449+
if (pid_file)
1450+
write_file(pid_file, "%"PRIuMAX, (uintmax_t) getpid());
14471451

1448-
if (pid_file)
1449-
write_file(pid_file, "%"PRIuMAX, (uintmax_t) getpid());
1452+
/* prepare argv for serving-processes */
1453+
strvec_push(&cld_argv, argv[0]); /* git-daemon */
1454+
strvec_push(&cld_argv, "--serve");
1455+
for (i = 1; i < argc; ++i)
1456+
strvec_push(&cld_argv, argv[i]);
14501457

1451-
/* prepare argv for serving-processes */
1452-
strvec_push(&cld_argv, argv[0]); /* git-daemon */
1453-
strvec_push(&cld_argv, "--serve");
1454-
for (i = 1; i < argc; ++i)
1455-
strvec_push(&cld_argv, argv[i]);
1458+
ret = serve(&listen_addr, listen_port, cred);
1459+
}
14561460

1457-
return serve(&listen_addr, listen_port, cred);
1461+
string_list_clear(&listen_addr, 0);
1462+
return ret;
14581463
}

decorate.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,18 @@ void *lookup_decoration(struct decoration *n, const struct object *obj)
8181
j = 0;
8282
}
8383
}
84+
85+
void clear_decoration(struct decoration *n, void (*free_cb)(void *))
86+
{
87+
if (free_cb) {
88+
unsigned int i;
89+
for (i = 0; i < n->size; i++) {
90+
void *d = n->entries[i].decoration;
91+
if (d)
92+
free_cb(d);
93+
}
94+
}
95+
96+
FREE_AND_NULL(n->entries);
97+
n->size = n->nr = 0;
98+
}

decorate.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,14 @@ void *add_decoration(struct decoration *n, const struct object *obj, void *decor
5858
*/
5959
void *lookup_decoration(struct decoration *n, const struct object *obj);
6060

61+
/*
62+
* Clear all decoration entries, releasing any memory used by the structure.
63+
* If free_cb is not NULL, it is called for every decoration value currently
64+
* stored.
65+
*
66+
* After clearing, the decoration struct can be used again. The "name" field is
67+
* retained.
68+
*/
69+
void clear_decoration(struct decoration *n, void (*free_cb)(void *));
70+
6171
#endif

line-log.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,3 +1327,13 @@ int line_log_filter(struct rev_info *rev)
13271327

13281328
return 0;
13291329
}
1330+
1331+
static void free_void_line_log_data(void *data)
1332+
{
1333+
free_line_log_data(data);
1334+
}
1335+
1336+
void line_log_free(struct rev_info *rev)
1337+
{
1338+
clear_decoration(&rev->line_log_data, free_void_line_log_data);
1339+
}

line-log.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ int line_log_process_ranges_arbitrary_commit(struct rev_info *rev,
6060

6161
int line_log_print(struct rev_info *rev, struct commit *commit);
6262

63+
void line_log_free(struct rev_info *rev);
64+
6365
#endif /* LINE_LOG_H */

revision.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,6 +3083,11 @@ static void release_revisions_mailmap(struct string_list *mailmap)
30833083

30843084
static void release_revisions_topo_walk_info(struct topo_walk_info *info);
30853085

3086+
static void free_void_commit_list(void *list)
3087+
{
3088+
free_commit_list(list);
3089+
}
3090+
30863091
void release_revisions(struct rev_info *revs)
30873092
{
30883093
free_commit_list(revs->commits);
@@ -3100,6 +3105,10 @@ void release_revisions(struct rev_info *revs)
31003105
diff_free(&revs->pruning);
31013106
reflog_walk_info_release(revs->reflog_info);
31023107
release_revisions_topo_walk_info(revs->topo_walk_info);
3108+
clear_decoration(&revs->children, free_void_commit_list);
3109+
clear_decoration(&revs->merge_simplification, free);
3110+
clear_decoration(&revs->treesame, free);
3111+
line_log_free(revs);
31033112
}
31043113

31053114
static void add_child(struct rev_info *revs, struct commit *parent, struct commit *child)

t/helper/test-example-decorate.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,7 @@ int cmd__example_decorate(int argc UNUSED, const char **argv UNUSED)
7272
if (objects_noticed != 2)
7373
BUG("should have 2 objects");
7474

75+
clear_decoration(&n, NULL);
76+
7577
return 0;
7678
}

t/t4217-log-limit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='git log with filter options limiting the output'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
test_expect_success 'setup test' '

t/t5811-proto-disable-git.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='test disabling of git-over-tcp in clone/fetch'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57
. "$TEST_DIRECTORY/lib-proto-disable.sh"
68
. "$TEST_DIRECTORY/lib-git-daemon.sh"

t/t9004-example.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='check that example code compiles and runs'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_expect_success 'decorate' '

0 commit comments

Comments
 (0)