Fix memory leak in submodule.c
The strbuf used in add_submodule_odb() was never released. So for every submodule - populated or not - we leaked its object directory name when using "git diff*" with the --submodule option. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jens Lehmann committed
Jan 31, 2010 at 17:43 UTC
de7a79608c94f7319b55060741d6be98826deccb
1 file changed
+9
-5
submodule.c
+9
-5
@@ -10,17 +10,19 @@ static int add_submodule_odb(const char *path)
10
{
11
struct strbuf objects_directory = STRBUF_INIT;
12
struct alternate_object_database *alt_odb;
13
+ int ret = 0;
14
15
strbuf_addf(&objects_directory, "%s/.git/objects/", path);
15
- if (!is_directory(objects_directory.buf))
16
- return -1;
17
-
16
+ if (!is_directory(objects_directory.buf)) {
17
+ ret = -1;
18
+ goto done;
19
+ }
20
/* avoid adding it twice */
21
for (alt_odb = alt_odb_list; alt_odb; alt_odb = alt_odb->next)
22
if (alt_odb->name - alt_odb->base == objects_directory.len &&
23
!strncmp(alt_odb->base, objects_directory.buf,
24
objects_directory.len))
23
- return 0;
25
+ goto done;
26
27
alt_odb = xmalloc(objects_directory.len + 42 + sizeof(*alt_odb));
28
alt_odb->next = alt_odb_list;
@@ -31,7 +33,9 @@ static int add_submodule_odb(const char *path)
33
alt_odb->name[41] = '\0';
34
alt_odb_list = alt_odb;
35
prepare_alt_odb();
34
- return 0;
36
+done:
37
+ strbuf_release(&objects_directory);
38
+ return ret;
39
}
40
41
void show_submodule_summary(FILE *f, const char *path,