From 5e0f47c3753c5ddd206ab3af6d2a231ad3da39c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 25 Jun 2014 21:20:39 +0200 Subject: [PATCH] pack: free the new pack struct if we fail to insert If we fail to insert the packfile in the map, make sure to free it. This makes the free function only attempt to remove its mwindows from the global list if we have opened the packfile to avoid accessing the list unlocked. --- src/mwindow.c | 5 ++++- src/pack.c | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mwindow.c b/src/mwindow.c index 0d6535056..a03a6597e 100644 --- a/src/mwindow.c +++ b/src/mwindow.c @@ -67,6 +67,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path) if (git_mwindow_files_init() < 0) { git_mutex_unlock(&git__mwindow_mutex); + git__free(packname); return -1; } @@ -93,8 +94,10 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path) git_strmap_insert(git__pack_cache, pack->pack_name, pack, error); git_mutex_unlock(&git__mwindow_mutex); - if (error < 0) + if (error < 0) { + git_packfile_free(pack); return -1; + } *out = pack; return 0; diff --git a/src/pack.c b/src/pack.c index 767efb6c3..22dbd5647 100644 --- a/src/pack.c +++ b/src/pack.c @@ -968,10 +968,10 @@ void git_packfile_free(struct git_pack_file *p) cache_free(&p->bases); - git_mwindow_free_all_locked(&p->mwf); - - if (p->mwf.fd >= 0) + if (p->mwf.fd >= 0) { + git_mwindow_free_all_locked(&p->mwf); p_close(p->mwf.fd); + } pack_index_free(p);