summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2013-01-12 18:38:19 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2013-01-12 18:44:58 +0100
commit96c9b9f0e538c7dd2f1041f471dd8a9a587bc43f (patch)
tree4ae83a2d1b37673b8e0f8cc72fdad42a18d08f10
parente2d2c6e57d122f381fb42b7df1c7a12819050490 (diff)
downloadlibgit2-96c9b9f0e538c7dd2f1041f471dd8a9a587bc43f.tar.gz
indexer: properly free the packfile resources
The indexer needs to call the packfile's free function so it takes care of freeing the caches. We still need to close the mwf descriptor manually so we can rename the packfile into its final name on Windows.
-rw-r--r--src/indexer.c8
-rw-r--r--src/odb_pack.c2
-rw-r--r--src/pack.c2
-rw-r--r--src/pack.h2
4 files changed, 7 insertions, 7 deletions
diff --git a/src/indexer.c b/src/indexer.c
index c1d599062..3f6b1076e 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -706,7 +706,9 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress *
goto on_error;
git_mwindow_free_all(&idx->pack->mwf);
+ /* We need to close the descriptor here so Windows doesn't choke on commit_at */
p_close(idx->pack->mwf.fd);
+ idx->pack->mwf.fd = -1;
if (index_path_stream(&filename, idx, ".pack") < 0)
goto on_error;
@@ -719,7 +721,6 @@ int git_indexer_stream_finalize(git_indexer_stream *idx, git_transfer_progress *
on_error:
git_mwindow_free_all(&idx->pack->mwf);
- p_close(idx->pack->mwf.fd);
git_filebuf_cleanup(&idx->index_file);
git_buf_free(&filename);
git_hash_ctx_cleanup(&ctx);
@@ -747,7 +748,7 @@ void git_indexer_stream_free(git_indexer_stream *idx)
git_vector_foreach(&idx->deltas, i, delta)
git__free(delta);
git_vector_free(&idx->deltas);
- git__free(idx->pack);
+ git_packfile_free(idx->pack);
git__free(idx);
}
@@ -1051,7 +1052,6 @@ void git_indexer_free(git_indexer *idx)
if (idx == NULL)
return;
- p_close(idx->pack->mwf.fd);
git_mwindow_file_deregister(&idx->pack->mwf);
git_vector_foreach(&idx->objects, i, e)
git__free(e);
@@ -1059,7 +1059,7 @@ void git_indexer_free(git_indexer *idx)
git_vector_foreach(&idx->pack->cache, i, pe)
git__free(pe);
git_vector_free(&idx->pack->cache);
- git__free(idx->pack);
+ git_packfile_free(idx->pack);
git__free(idx);
}
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 9d0c4c0e7..9779ecd25 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -538,7 +538,7 @@ static void pack_backend__free(git_odb_backend *_backend)
for (i = 0; i < backend->packs.length; ++i) {
struct git_pack_file *p = git_vector_get(&backend->packs, i);
- packfile_free(p);
+ git_packfile_free(p);
}
git_vector_free(&backend->packs);
diff --git a/src/pack.c b/src/pack.c
index dcf9dd178..3490c8bb9 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -794,7 +794,7 @@ static struct git_pack_file *packfile_alloc(size_t extra)
}
-void packfile_free(struct git_pack_file *p)
+void git_packfile_free(struct git_pack_file *p)
{
assert(p);
diff --git a/src/pack.h b/src/pack.h
index db57e57d2..6c43d8f5b 100644
--- a/src/pack.h
+++ b/src/pack.h
@@ -139,7 +139,7 @@ git_off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
git_off_t *curpos, git_otype type,
git_off_t delta_obj_offset);
-void packfile_free(struct git_pack_file *p);
+void git_packfile_free(struct git_pack_file *p);
int git_packfile_check(struct git_pack_file **pack_out, const char *path);
int git_pack_entry_find(
struct git_pack_entry *e,