@@ -250,11 +250,15 @@ func (ix *IndexWriter) Flush() {
250250 }
251251 ix .main .writeString (trailerMagic )
252252
253+ ix .nameData .file .Close ()
253254 os .Remove (ix .nameData .name )
254255 for _ , f := range ix .postFile {
256+ f .Close ()
255257 os .Remove (f .Name ())
256258 }
259+ ix .nameIndex .file .Close ()
257260 os .Remove (ix .nameIndex .name )
261+ ix .postIndex .file .Close ()
258262 os .Remove (ix .postIndex .name )
259263
260264 log .Printf ("%d data bytes, %d index bytes" , ix .totalBytes , ix .main .offset ())
@@ -355,6 +359,9 @@ func (ix *IndexWriter) mergePost(out *bufWriter) {
355359 break
356360 }
357361 }
362+ for _ , mappedData := range h .mappedData {
363+ unmmapFile (mappedData )
364+ }
358365}
359366
360367// A postChunk represents a chunk of post entries flushed to disk or
@@ -368,13 +375,17 @@ const postBuf = 4096
368375
369376// A postHeap is a heap (priority queue) of postChunks.
370377type postHeap struct {
371- ch []* postChunk
378+ ch []* postChunk
379+ mappedData []* mmapData
372380}
373381
374382func (h * postHeap ) addFile (f * os.File ) {
375- data := mmapFile (f ).d
383+ mappedData := mmapFile (f )
384+ data := mappedData .d
376385 m := (* [npost ]postEntry )(unsafe .Pointer (& data [0 ]))[:len (data )/ 8 ]
377386 h .addMem (m )
387+ // Make sure we close the mmap memory once we're done with it
388+ h .mappedData = append (h .mappedData , (& mappedData ))
378389}
379390
380391func (h * postHeap ) addMem (x []postEntry ) {
0 commit comments