Commit 1d8943c6 by Carlos Martin Nieto

mwindow: allow memory-window files to deregister

Once a file is registered, there is no way to deregister it, even
after the structure that contains it is no longer needed and has been
freed. This may be the source of #624.

Allow and use the deregister function to remove our file from the
global list.
parent 1de44c24
......@@ -773,6 +773,7 @@ int git_indexer_write(git_indexer *idx)
cleanup:
git_mwindow_free_all(&idx->pack->mwf);
git_mwindow_file_deregister(&idx->pack->mwf);
if (error < 0)
git_filebuf_cleanup(&idx->file);
git_buf_free(&filename);
......@@ -886,6 +887,7 @@ void git_indexer_free(git_indexer *idx)
return;
p_close(idx->pack->mwf.fd);
git_mwindow_file_deregister(&idx->pack->mwf);
git_vector_foreach(&idx->objects, i, e)
git__free(e);
git_vector_free(&idx->objects);
......
......@@ -261,6 +261,23 @@ int git_mwindow_file_register(git_mwindow_file *mwf)
return git_vector_insert(&ctl->windowfiles, mwf);
}
int git_mwindow_file_deregister(git_mwindow_file *mwf)
{
git_mwindow_ctl *ctl = &GIT_GLOBAL->mem_ctl;
git_mwindow_file *cur;
unsigned int i;
git_vector_foreach(&ctl->windowfiles, i, cur) {
if (cur == mwf) {
git_vector_remove(&ctl->windowfiles, i);
return 0;
}
}
giterr_set(GITERR_ODB, "Failed to find the memory window file to deregister");
return -1;
}
void git_mwindow_close(git_mwindow **window)
{
git_mwindow *w = *window;
......
......@@ -40,6 +40,7 @@ void git_mwindow_free_all(git_mwindow_file *mwf);
unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, git_off_t offset, size_t extra, unsigned int *left);
void git_mwindow_scan_lru(git_mwindow_file *mwf, git_mwindow **lru_w, git_mwindow **lru_l);
int git_mwindow_file_register(git_mwindow_file *mwf);
int git_mwindow_file_deregister(git_mwindow_file *mwf);
void git_mwindow_close(git_mwindow **w_cursor);
#endif
......@@ -535,6 +535,7 @@ void packfile_free(struct git_pack_file *p)
/* clear_delta_base_cache(); */
git_mwindow_free_all(&p->mwf);
git_mwindow_file_deregister(&p->mwf);
if (p->mwf.fd != -1)
p_close(p->mwf.fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment