Skip to content

Commit dc4cd76

Browse files
meyeringgitster
authored andcommitted
plug a few coverity-spotted leaks
Signed-off-by: Jim Meyering <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 28eb1af commit dc4cd76

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

builtin/cat-file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ static int batch_one_object(const char *obj_name, int print_contents)
187187
if (type <= 0) {
188188
printf("%s missing\n", obj_name);
189189
fflush(stdout);
190+
if (print_contents == BATCH)
191+
free(contents);
190192
return 0;
191193
}
192194

builtin/diff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ static int builtin_diff_combined(struct rev_info *revs,
182182
hashcpy((unsigned char *)(parent + i), ent[i].item->sha1);
183183
diff_tree_combined(parent[0], parent + 1, ents - 1,
184184
revs->dense_combined_merges, revs);
185+
free(parent);
185186
return 0;
186187
}
187188

builtin/update-index.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ static int add_one_path(struct cache_entry *old, const char *path, int len, stru
100100
ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
101101

102102
if (index_path(ce->sha1, path, st,
103-
info_only ? 0 : HASH_WRITE_OBJECT))
103+
info_only ? 0 : HASH_WRITE_OBJECT)) {
104+
free(ce);
104105
return -1;
106+
}
105107
option = allow_add ? ADD_CACHE_OK_TO_ADD : 0;
106108
option |= allow_replace ? ADD_CACHE_OK_TO_REPLACE : 0;
107109
if (add_cache_entry(ce, option))

remote-curl.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -811,19 +811,21 @@ static void parse_push(struct strbuf *buf)
811811

812812
strbuf_reset(buf);
813813
if (strbuf_getline(buf, stdin, '\n') == EOF)
814-
return;
814+
goto free_specs;
815815
if (!*buf->buf)
816816
break;
817817
} while (1);
818818

819819
if (push(nr_spec, specs))
820820
exit(128); /* error already reported */
821-
for (i = 0; i < nr_spec; i++)
822-
free(specs[i]);
823-
free(specs);
824821

825822
printf("\n");
826823
fflush(stdout);
824+
825+
free_specs:
826+
for (i = 0; i < nr_spec; i++)
827+
free(specs[i]);
828+
free(specs);
827829
}
828830

829831
int main(int argc, const char **argv)

0 commit comments

Comments
 (0)