mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 18:38:58 +00:00
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.
This commit is contained in:
parent
1de44c2493
commit
1d8943c640
@ -773,6 +773,7 @@ int git_indexer_write(git_indexer *idx)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
git_mwindow_free_all(&idx->pack->mwf);
|
git_mwindow_free_all(&idx->pack->mwf);
|
||||||
|
git_mwindow_file_deregister(&idx->pack->mwf);
|
||||||
if (error < 0)
|
if (error < 0)
|
||||||
git_filebuf_cleanup(&idx->file);
|
git_filebuf_cleanup(&idx->file);
|
||||||
git_buf_free(&filename);
|
git_buf_free(&filename);
|
||||||
@ -886,6 +887,7 @@ void git_indexer_free(git_indexer *idx)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
p_close(idx->pack->mwf.fd);
|
p_close(idx->pack->mwf.fd);
|
||||||
|
git_mwindow_file_deregister(&idx->pack->mwf);
|
||||||
git_vector_foreach(&idx->objects, i, e)
|
git_vector_foreach(&idx->objects, i, e)
|
||||||
git__free(e);
|
git__free(e);
|
||||||
git_vector_free(&idx->objects);
|
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);
|
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)
|
void git_mwindow_close(git_mwindow **window)
|
||||||
{
|
{
|
||||||
git_mwindow *w = *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);
|
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);
|
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_register(git_mwindow_file *mwf);
|
||||||
|
int git_mwindow_file_deregister(git_mwindow_file *mwf);
|
||||||
void git_mwindow_close(git_mwindow **w_cursor);
|
void git_mwindow_close(git_mwindow **w_cursor);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -535,6 +535,7 @@ void packfile_free(struct git_pack_file *p)
|
|||||||
|
|
||||||
/* clear_delta_base_cache(); */
|
/* clear_delta_base_cache(); */
|
||||||
git_mwindow_free_all(&p->mwf);
|
git_mwindow_free_all(&p->mwf);
|
||||||
|
git_mwindow_file_deregister(&p->mwf);
|
||||||
|
|
||||||
if (p->mwf.fd != -1)
|
if (p->mwf.fd != -1)
|
||||||
p_close(p->mwf.fd);
|
p_close(p->mwf.fd);
|
||||||
|
Loading…
Reference in New Issue
Block a user