mirror of
https://github.com/git/git.git
synced 2026-03-10 17:18:43 +01:00
Merge branch 'jk/unleak-mmap' into jch
Plug a few leaks where mmap'ed memory regions are not unmapped. * jk/unleak-mmap: meson: turn on NO_MMAP when building with LSan Makefile: turn on NO_MMAP when building with LSan object-file: fix mmap() leak in odb_source_loose_read_object_stream() pack-revindex: avoid double-loading .rev files check_connected(): fix leak of pack-index mmap check_connected(): delay opening new_pack
This commit is contained in:
1
Makefile
1
Makefile
@@ -1605,6 +1605,7 @@ BASIC_CFLAGS += -DSHA1DC_FORCE_ALIGNED_ACCESS
|
||||
endif
|
||||
ifneq ($(filter leak,$(SANITIZERS)),)
|
||||
BASIC_CFLAGS += -O0
|
||||
NO_MMAP = CatchMapLeaks
|
||||
SANITIZE_LEAK = YesCompiledWithIt
|
||||
endif
|
||||
ifneq ($(filter address,$(SANITIZERS)),)
|
||||
|
||||
38
connected.c
38
connected.c
@@ -45,20 +45,6 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
|
||||
return err;
|
||||
}
|
||||
|
||||
if (transport && transport->smart_options &&
|
||||
transport->smart_options->self_contained_and_connected &&
|
||||
transport->pack_lockfiles.nr == 1 &&
|
||||
strip_suffix(transport->pack_lockfiles.items[0].string,
|
||||
".keep", &base_len)) {
|
||||
struct strbuf idx_file = STRBUF_INIT;
|
||||
strbuf_add(&idx_file, transport->pack_lockfiles.items[0].string,
|
||||
base_len);
|
||||
strbuf_addstr(&idx_file, ".idx");
|
||||
new_pack = add_packed_git(the_repository, idx_file.buf,
|
||||
idx_file.len, 1);
|
||||
strbuf_release(&idx_file);
|
||||
}
|
||||
|
||||
if (repo_has_promisor_remote(the_repository)) {
|
||||
/*
|
||||
* For partial clones, we don't want to have to do a regular
|
||||
@@ -90,7 +76,6 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
|
||||
promisor_pack_found:
|
||||
;
|
||||
} while ((oid = fn(cb_data)) != NULL);
|
||||
free(new_pack);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -127,15 +112,27 @@ no_promisor_pack_found:
|
||||
else
|
||||
rev_list.no_stderr = opt->quiet;
|
||||
|
||||
if (start_command(&rev_list)) {
|
||||
free(new_pack);
|
||||
if (start_command(&rev_list))
|
||||
return error(_("Could not run 'git rev-list'"));
|
||||
}
|
||||
|
||||
sigchain_push(SIGPIPE, SIG_IGN);
|
||||
|
||||
rev_list_in = xfdopen(rev_list.in, "w");
|
||||
|
||||
if (transport && transport->smart_options &&
|
||||
transport->smart_options->self_contained_and_connected &&
|
||||
transport->pack_lockfiles.nr == 1 &&
|
||||
strip_suffix(transport->pack_lockfiles.items[0].string,
|
||||
".keep", &base_len)) {
|
||||
struct strbuf idx_file = STRBUF_INIT;
|
||||
strbuf_add(&idx_file, transport->pack_lockfiles.items[0].string,
|
||||
base_len);
|
||||
strbuf_addstr(&idx_file, ".idx");
|
||||
new_pack = add_packed_git(the_repository, idx_file.buf,
|
||||
idx_file.len, 1);
|
||||
strbuf_release(&idx_file);
|
||||
}
|
||||
|
||||
do {
|
||||
/*
|
||||
* If index-pack already checked that:
|
||||
@@ -162,6 +159,9 @@ no_promisor_pack_found:
|
||||
err = error_errno(_("failed to close rev-list's stdin"));
|
||||
|
||||
sigchain_pop(SIGPIPE);
|
||||
free(new_pack);
|
||||
if (new_pack) {
|
||||
close_pack(new_pack);
|
||||
free(new_pack);
|
||||
}
|
||||
return finish_command(&rev_list) || err;
|
||||
}
|
||||
|
||||
@@ -1446,7 +1446,7 @@ else
|
||||
'getpagesize' : [],
|
||||
}
|
||||
|
||||
if get_option('b_sanitize').contains('address')
|
||||
if get_option('b_sanitize').contains('address') or get_option('b_sanitize').contains('leak')
|
||||
libgit_c_args += '-DNO_MMAP'
|
||||
libgit_sources += 'compat/mmap.c'
|
||||
else
|
||||
|
||||
@@ -2211,7 +2211,7 @@ int odb_source_loose_read_object_stream(struct odb_read_stream **out,
|
||||
return 0;
|
||||
error:
|
||||
git_inflate_end(&st->z);
|
||||
munmap(st->mapped, st->mapsize);
|
||||
munmap(mapped, mapsize);
|
||||
free(st);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -277,6 +277,10 @@ int load_pack_revindex_from_disk(struct packed_git *p)
|
||||
{
|
||||
char *revindex_name;
|
||||
int ret;
|
||||
|
||||
if (p->revindex_data)
|
||||
return 0;
|
||||
|
||||
if (open_pack_index(p))
|
||||
return -1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user