Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7561f98

Browse files
committed
Fix for memory leak issue in indexer.c, that surfaces on windows
1 parent 4d86cae commit 7561f98

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/indexer.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ int git_indexer_new(
120120
idx->progress_cb = progress_cb;
121121
idx->progress_payload = progress_payload;
122122
idx->mode = mode ? mode : GIT_PACK_FILE_MODE;
123+
git_hash_ctx_init(&idx->hash_ctx);
123124
git_hash_ctx_init(&idx->trailer);
124125

125126
error = git_buf_joinpath(&path, prefix, suff);
@@ -265,7 +266,6 @@ static int store_object(git_indexer *idx)
265266
struct entry *entry;
266267
git_off_t entry_size;
267268
struct git_pack_entry *pentry;
268-
git_hash_ctx *ctx = &idx->hash_ctx;
269269
git_off_t entry_start = idx->entry_start;
270270

271271
entry = git__calloc(1, sizeof(*entry));
@@ -274,7 +274,7 @@ static int store_object(git_indexer *idx)
274274
pentry = git__calloc(1, sizeof(struct git_pack_entry));
275275
GITERR_CHECK_ALLOC(pentry);
276276

277-
git_hash_final(&oid, ctx);
277+
git_hash_final(&oid, &idx->hash_ctx);
278278
entry_size = idx->off - entry_start;
279279
if (entry_start > UINT31_MAX) {
280280
entry->offset = UINT32_MAX;
@@ -557,7 +557,7 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
557557

558558
git_mwindow_close(&w);
559559
idx->entry_start = entry_start;
560-
git_hash_ctx_init(&idx->hash_ctx);
560+
git_hash_init(&idx->hash_ctx);
561561

562562
if (type == GIT_OBJ_REF_DELTA || type == GIT_OBJ_OFS_DELTA) {
563563
error = advance_delta_offset(idx, type);
@@ -843,12 +843,10 @@ static int update_header_and_rehash(git_indexer *idx, git_transfer_progress *sta
843843
git_mwindow *w = NULL;
844844
git_mwindow_file *mwf;
845845
unsigned int left;
846-
git_hash_ctx *ctx;
847846

848847
mwf = &idx->pack->mwf;
849-
ctx = &idx->trailer;
850848

851-
git_hash_ctx_init(ctx);
849+
git_hash_init(&idx->trailer);
852850

853851

854852
/* Update the header to include the numer of local objects we injected */
@@ -1061,5 +1059,7 @@ void git_indexer_free(git_indexer *idx)
10611059
git_mutex_unlock(&git__mwindow_mutex);
10621060
}
10631061

1062+
git_hash_ctx_cleanup(&idx->trailer);
1063+
git_hash_ctx_cleanup(&idx->hash_ctx);
10641064
git__free(idx);
10651065
}

0 commit comments

Comments
 (0)