plug a few coverity-spotted leaks
Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jim Meyering committed
Jun 20, 2011 at 09:40 UTC
dc4cd767108532161d27554162a8742f5b607eb8
4 files changed
+12
-5
builtin/cat-file.c
+2
@@ -187,6 +187,8 @@ static int batch_one_object(const char *obj_name, int print_contents)
187
if (type <= 0) {
188
printf("%s missing\n", obj_name);
189
fflush(stdout);
190
+ if (print_contents == BATCH)
191
+ free(contents);
192
return 0;
193
}
194
builtin/diff.c
+1
@@ -182,6 +182,7 @@ static int builtin_diff_combined(struct rev_info *revs,
182
hashcpy((unsigned char *)(parent + i), ent[i].item->sha1);
183
diff_tree_combined(parent[0], parent + 1, ents - 1,
184
revs->dense_combined_merges, revs);
185
+ free(parent);
186
return 0;
187
}
188
builtin/update-index.c
+3
-1
@@ -100,8 +100,10 @@ static int add_one_path(struct cache_entry *old, const char *path, int len, stru
100
ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
101
102
if (index_path(ce->sha1, path, st,
103
- info_only ? 0 : HASH_WRITE_OBJECT))
103
+ info_only ? 0 : HASH_WRITE_OBJECT)) {
104
+ free(ce);
105
return -1;
106
+ }
107
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
108
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
109
if (add_cache_entry(ce, option))
remote-curl.c
+6
-4
@@ -811,19 +811,21 @@ static void parse_push(struct strbuf *buf)
811
812
strbuf_reset(buf);
813
if (strbuf_getline(buf, stdin, '\n') == EOF)
814
- return;
814
+ goto free_specs;
815
if (!*buf->buf)
816
break;
817
} while (1);
818
819
if (push(nr_spec, specs))
820
exit(128); /* error already reported */
821
- for (i = 0; i < nr_spec; i++)
822
- free(specs[i]);
823
- free(specs);
821
822
printf("\n");
823
fflush(stdout);
824
+
825
+ free_specs:
826
+ for (i = 0; i < nr_spec; i++)
827
+ free(specs[i]);
828
+ free(specs);
829
}
830
831
int main(int argc, const char **argv)