Skip to content

Commit 553c622

Browse files
committed
Merge branch 'sb/leaks'
* sb/leaks: http: release the memory of a http pack request as well read-cache: fix memleak add_to_index(): free unused cache-entry commit.c: fix a memory leak http-push: remove unneeded cleanup merge-recursive: fix memleaks merge-blobs.c: fix a memleak builtin/apply.c: fix a memleak update-index: fix a memleak read-cache: free cache entry in add_to_index in case of early return
2 parents 2dfb2e0 + 826aed5 commit 553c622

8 files changed

+27
-15
lines changed

builtin/apply.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -2776,7 +2776,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
27762776
default:
27772777
if (apply_verbosely)
27782778
error(_("invalid start of line: '%c'"), first);
2779-
return -1;
2779+
applied_pos = -1;
2780+
goto out;
27802781
}
27812782
if (added_blank_line) {
27822783
if (!new_blank_lines_at_end)
@@ -2915,6 +2916,7 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
29152916
(int)(old - oldlines), oldlines);
29162917
}
29172918

2919+
out:
29182920
free(oldlines);
29192921
strbuf_release(&newlines);
29202922
free(preimage.line_allocated);

builtin/commit.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static int commit_index_files(void)
229229
static int list_paths(struct string_list *list, const char *with_tree,
230230
const char *prefix, const struct pathspec *pattern)
231231
{
232-
int i;
232+
int i, ret;
233233
char *m;
234234

235235
if (!pattern->nr)
@@ -256,7 +256,9 @@ static int list_paths(struct string_list *list, const char *with_tree,
256256
item->util = item; /* better a valid pointer than a fake one */
257257
}
258258

259-
return report_path_error(m, pattern, prefix);
259+
ret = report_path_error(m, pattern, prefix);
260+
free(m);
261+
return ret;
260262
}
261263

262264
static void add_remove_files(struct string_list *list)

builtin/update-index.c

+1
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ static int do_reupdate(int ac, const char **av,
584584
path = xstrdup(ce->name);
585585
update_one(path);
586586
free(path);
587+
free(old);
587588
if (save_nr != active_nr)
588589
goto redo;
589590
}

http-push.c

-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ static void start_fetch_packed(struct transfer_request *request)
316316

317317
preq = new_http_pack_request(target, repo->url);
318318
if (preq == NULL) {
319-
release_http_pack_request(preq);
320319
repo->can_update_info_refs = 0;
321320
return;
322321
}

http.c

+1
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,7 @@ void release_http_pack_request(struct http_pack_request *preq)
14621462
}
14631463
preq->slot = NULL;
14641464
free(preq->url);
1465+
free(preq);
14651466
}
14661467

14671468
int finish_http_pack_request(struct http_pack_request *preq)

merge-blobs.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
1414
buf = read_sha1_file(obj->object.sha1, &type, &size);
1515
if (!buf)
1616
return -1;
17-
if (type != OBJ_BLOB)
17+
if (type != OBJ_BLOB) {
18+
free(buf);
1819
return -1;
20+
}
1921
f->ptr = buf;
2022
f->size = size;
2123
return 0;

merge-recursive.c

+3
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,9 @@ int merge_trees(struct merge_options *o,
18581858
string_list_clear(re_head, 0);
18591859
string_list_clear(entries, 1);
18601860

1861+
free(re_merge);
1862+
free(re_head);
1863+
free(entries);
18611864
}
18621865
else
18631866
clean = 1;

read-cache.c

+12-10
Original file line numberDiff line numberDiff line change
@@ -681,15 +681,18 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
681681
alias = index_file_exists(istate, ce->name, ce_namelen(ce), ignore_case);
682682
if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) {
683683
/* Nothing changed, really */
684-
free(ce);
685684
if (!S_ISGITLINK(alias->ce_mode))
686685
ce_mark_uptodate(alias);
687686
alias->ce_flags |= CE_ADDED;
687+
688+
free(ce);
688689
return 0;
689690
}
690691
if (!intent_only) {
691-
if (index_path(ce->sha1, path, st, HASH_WRITE_OBJECT))
692+
if (index_path(ce->sha1, path, st, HASH_WRITE_OBJECT)) {
693+
free(ce);
692694
return error("unable to index file %s", path);
695+
}
693696
} else
694697
set_object_name_for_intent_to_add_entry(ce);
695698

@@ -704,9 +707,11 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
704707
ce->ce_mode == alias->ce_mode);
705708

706709
if (pretend)
707-
;
708-
else if (add_index_entry(istate, ce, add_option))
709-
return error("unable to add %s to index",path);
710+
free(ce);
711+
else if (add_index_entry(istate, ce, add_option)) {
712+
free(ce);
713+
return error("unable to add %s to index", path);
714+
}
710715
if (verbose && !was_same)
711716
printf("add '%s'\n", path);
712717
return 0;
@@ -743,12 +748,9 @@ struct cache_entry *make_cache_entry(unsigned int mode,
743748
ce->ce_mode = create_ce_mode(mode);
744749

745750
ret = refresh_cache_entry(ce, refresh_options);
746-
if (!ret) {
751+
if (ret != ce)
747752
free(ce);
748-
return NULL;
749-
} else {
750-
return ret;
751-
}
753+
return ret;
752754
}
753755

754756
int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)

0 commit comments

Comments
 (0)