Commits

Carlos Martin Nieto  committed 951139d

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.

  • Participants
  • Parent commits 8ccdce9
  • Branches development, ubuntu

Comments (0)

Files changed (4)

File src/indexer.c

 
 cleanup:
 	git_mwindow_free_all(&idx->pack->mwf);
+	git_mwindow_file_deregister(&idx->pack->mwf);
 	if (error < GIT_SUCCESS)
 		git_filebuf_cleanup(&idx->file);
 
 		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);

File src/mwindow.c

 	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;
+		}
+	}
+
+	return git__throw(GIT_ERROR, "Failed to find the memory window file to deregister");
+}
+
 void git_mwindow_close(git_mwindow **window)
 {
 	git_mwindow *w = *window;

File src/mwindow.h

 unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, git_off_t offset, int 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
 
 	/* 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);