Valgrind leaks

#1

With version 8.1.4:

$ valgrind --leak-check=full --show-leak-kinds=all swipl -g 'write(hi)' -t halt.

==8063== Memcheck, a memory error detector
==8063== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==8063== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==8063== Command: swipl -g write(hi) -t halt.
==8063== 
hi==8063== Invalid free() / delete / delete[] / realloc()
==8063==    at 0x48389AB: free (vg_replace_malloc.c:530)
==8063==    by 0x4BD5A1F: ??? (in /usr/lib/libdl-2.28.so)
==8063==    by 0x4ED416A: __libc_freeres (in /usr/lib/libc-2.28.so)
==8063==    by 0x482D1AE: _vgnU_freeres (vg_preloaded.c:77)
==8063==    by 0x4DA2561: __run_exit_handlers (in /usr/lib/libc-2.28.so)
==8063==    by 0x4DA258D: exit (in /usr/lib/libc-2.28.so)
==8063==    by 0x1421D1: PL_halt (pl-fli.c:4612)
==8063==    by 0x1AE380: pl_halt (pl-prims.c:4746)
==8063==    by 0x1544FF: PL_next_solution (pl-vmi.c:3771)
==8063==    by 0x1B0B3B: query_loop (pl-pro.c:131)
==8063==    by 0x1B15B4: prologToplevel (pl-pro.c:466)
==8063==    by 0x142176: PL_toplevel (pl-fli.c:4568)
==8063==  Address 0x2dc1a0 is 0 bytes inside data symbol "PL_local_data"
==8063== 
==8063== 
==8063== HEAP SUMMARY:
==8063==     in use at exit: 2,323,882 bytes in 19,467 blocks
==8063==   total heap usage: 46,173 allocs, 26,707 frees, 8,755,657 bytes allocated
==8063== 
==8063== 3 bytes in 1 blocks are indirectly lost in loss record 1 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x4DF149E: strdup (in /usr/lib/libc-2.28.so)
==8063==    by 0x26688E: init_locale_strings (pl-locale.c:107)
==8063==    by 0x2669A3: new_locale (pl-locale.c:133)
==8063==    by 0x268243: initLocale (pl-locale.c:840)
==8063==    by 0x1D4BED: setupProlog (pl-setup.c:137)
==8063==    by 0x20C966: PL_initialise (pl-init.c:963)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 8 bytes in 1 blocks are indirectly lost in loss record 2 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x26675B: my_wcsdup (pl-locale.c:75)
==8063==    by 0x2667E8: ls_to_wcs (pl-locale.c:94)
==8063==    by 0x266851: init_locale_strings (pl-locale.c:105)
==8063==    by 0x2669A3: new_locale (pl-locale.c:133)
==8063==    by 0x268243: initLocale (pl-locale.c:840)
==8063==    by 0x1D4BED: setupProlog (pl-setup.c:137)
==8063==    by 0x20C966: PL_initialise (pl-init.c:963)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 8 bytes in 1 blocks are indirectly lost in loss record 3 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x26675B: my_wcsdup (pl-locale.c:75)
==8063==    by 0x2667E8: ls_to_wcs (pl-locale.c:94)
==8063==    by 0x266873: init_locale_strings (pl-locale.c:106)
==8063==    by 0x2669A3: new_locale (pl-locale.c:133)
==8063==    by 0x268243: initLocale (pl-locale.c:840)
==8063==    by 0x1D4BED: setupProlog (pl-setup.c:137)
==8063==    by 0x20C966: PL_initialise (pl-init.c:963)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 8 bytes in 1 blocks are indirectly lost in loss record 4 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x12B866: PL_malloc (pl-alloc.c:1189)
==8063==    by 0x1B764A: registerDirtyDefinition (pl-proc.c:2020)
==8063==    by 0x1B6015: retractClauseDefinition (pl-proc.c:1398)
==8063==    by 0x1D45E5: pl_erase1_va (pl-rec.c:2355)
==8063==    by 0x154461: PL_next_solution (pl-vmi.c:3747)
==8063==    by 0x1334ED: callCleanupHandler (pl-wam.c:651)
==8063==    by 0x1335FB: frameFinished (pl-wam.c:670)
==8063==    by 0x155CC8: PL_next_solution (pl-vmi.c:4192)
==8063==    by 0x1B0B3B: query_loop (pl-pro.c:131)
==8063==    by 0x1B15B4: prologToplevel (pl-pro.c:466)
==8063==    by 0x20CCA4: PL_initialise (pl-init.c:1035)
==8063== 
==8063== 8 bytes in 1 blocks are indirectly lost in loss record 5 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x12B866: PL_malloc (pl-alloc.c:1189)
==8063==    by 0x1B764A: registerDirtyDefinition (pl-proc.c:2020)
==8063==    by 0x1B6015: retractClauseDefinition (pl-proc.c:1398)
==8063==    by 0x1B9455: pl_retractall (pl-proc.c:2687)
==8063==    by 0x1544FF: PL_next_solution (pl-vmi.c:3771)
==8063==    by 0x1B0B3B: query_loop (pl-pro.c:131)
==8063==    by 0x1B15B4: prologToplevel (pl-pro.c:466)
==8063==    by 0x20CCA4: PL_initialise (pl-init.c:1035)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 8 bytes in 1 blocks are indirectly lost in loss record 6 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x12B866: PL_malloc (pl-alloc.c:1189)
==8063==    by 0x1B764A: registerDirtyDefinition (pl-proc.c:2020)
==8063==    by 0x1BA307: setDynamicDefinition_unlocked (pl-proc.c:2986)
==8063==    by 0x1BA366: setDynamicDefinition (pl-proc.c:3001)
==8063==    by 0x1BA594: setAttrDefinition (pl-proc.c:3070)
==8063==    by 0x203525: setAttrProcedureSource (pl-srcfile.c:1113)
==8063==    by 0x1BA7D2: pl_set_predicate_attribute (pl-proc.c:3124)
==8063==    by 0x1545F1: PL_next_solution (pl-vmi.c:3791)
==8063==    by 0x1B0B3B: query_loop (pl-pro.c:131)
==8063==    by 0x1B15B4: prologToplevel (pl-pro.c:466)
==8063==    by 0x20CCA4: PL_initialise (pl-init.c:1035)
==8063== 
==8063== 8 bytes in 1 blocks are indirectly lost in loss record 7 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x12B866: PL_malloc (pl-alloc.c:1189)
==8063==    by 0x1B764A: registerDirtyDefinition (pl-proc.c:2020)
==8063==    by 0x1B6015: retractClauseDefinition (pl-proc.c:1398)
==8063==    by 0x1D45E5: pl_erase1_va (pl-rec.c:2355)
==8063==    by 0x154461: PL_next_solution (pl-vmi.c:3747)
==8063==    by 0x1B0B3B: query_loop (pl-pro.c:131)
==8063==    by 0x1B15B4: prologToplevel (pl-pro.c:466)
==8063==    by 0x20CCA4: PL_initialise (pl-init.c:1035)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 8 bytes in 1 blocks are definitely lost in loss record 8 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x18243D: registerBuiltins (pl-ext.c:319)
==8063==    by 0x1827ED: initBuildIns (pl-ext.c:460)
==8063==    by 0x1D4B35: setupProlog (pl-setup.c:123)
==8063==    by 0x20C966: PL_initialise (pl-init.c:963)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 8 bytes in 1 blocks are definitely lost in loss record 9 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x182E6E: initBuildIns (pl-ext.c:484)
==8063==    by 0x1D4B35: setupProlog (pl-setup.c:123)
==8063==    by 0x20C966: PL_initialise (pl-init.c:963)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 8 bytes in 1 blocks are definitely lost in loss record 10 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x17261E: lookupBodyProcedure (pl-comp.c:2527)
==8063==    by 0x172F65: compileSubClause (pl-comp.c:2722)
==8063==    by 0x170DD9: compileBody (pl-comp.c:2085)
==8063==    by 0x16FD4F: compileBody (pl-comp.c:1946)
==8063==    by 0x16EEDB: compileClause (pl-comp.c:1710)
==8063==    by 0x177547: assert_term (pl-comp.c:3663)
==8063==    by 0x177D41: record_clause (pl-comp.c:3861)
==8063==    by 0x177DD1: pl_record_clause3_va (pl-comp.c:3876)
==8063== 
==8063== 8 bytes in 1 blocks are definitely lost in loss record 11 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x17261E: lookupBodyProcedure (pl-comp.c:2527)
==8063==    by 0x172F65: compileSubClause (pl-comp.c:2722)
==8063==    by 0x170DD9: compileBody (pl-comp.c:2085)
==8063==    by 0x16FF07: compileBody (pl-comp.c:1955)
==8063==    by 0x16EEDB: compileClause (pl-comp.c:1710)
==8063==    by 0x177547: assert_term (pl-comp.c:3663)
==8063==    by 0x177D41: record_clause (pl-comp.c:3861)
==8063==    by 0x177DD1: pl_record_clause3_va (pl-comp.c:3876)
==8063== 
==8063== 16 bytes in 1 blocks are indirectly lost in loss record 12 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x12F927: insertIndex (pl-index.c:1807)
==8063==    by 0x12F2C7: hashDefinition (pl-index.c:1605)
==8063==    by 0x12CAA6: first_clause_guarded (pl-index.c:500)
==8063==    by 0x12CD6A: firstClause (pl-index.c:544)
==8063==    by 0x150D26: PL_next_solution (pl-vmi.c:2845)
==8063==    by 0x141007: PL_call_predicate (pl-fli.c:4129)
==8063==    by 0x143899: PL_license (pl-fli.c:5294)
==8063==    by 0x14393A: registerForeignLicenses (pl-fli.c:5315)
==8063==    by 0x20CBE9: PL_initialise (pl-init.c:1022)
==8063== 
==8063== 16 bytes in 1 blocks are indirectly lost in loss record 13 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x13153D: bestHash (pl-index.c:2453)
==8063==    by 0x12CA81: first_clause_guarded (pl-index.c:497)
==8063==    by 0x12C09A: nextClauseFromBucket (pl-index.c:280)
==8063==    by 0x12CB8C: first_clause_guarded (pl-index.c:510)
==8063==    by 0x12CD6A: firstClause (pl-index.c:544)
==8063==    by 0x150D26: PL_next_solution (pl-vmi.c:2845)
==8063==    by 0x1B0B3B: query_loop (pl-pro.c:131)
==8063==    by 0x1B15B4: prologToplevel (pl-pro.c:466)
==8063==    by 0x20CCA4: PL_initialise (pl-init.c:1035)
==8063== 
==8063== 16 bytes in 1 blocks are indirectly lost in loss record 14 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x12F927: insertIndex (pl-index.c:1807)
==8063==    by 0x12F2C7: hashDefinition (pl-index.c:1605)
==8063==    by 0x12CAA6: first_clause_guarded (pl-index.c:500)
==8063==    by 0x12C09A: nextClauseFromBucket (pl-index.c:280)
==8063==    by 0x12CB8C: first_clause_guarded (pl-index.c:510)
==8063==    by 0x12CD6A: firstClause (pl-index.c:544)
==8063==    by 0x150D26: PL_next_solution (pl-vmi.c:2845)
==8063==    by 0x1B0B3B: query_loop (pl-pro.c:131)
==8063==    by 0x1B15B4: prologToplevel (pl-pro.c:466)
==8063== 
==8063== 16 bytes in 1 blocks are indirectly lost in loss record 15 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x12F927: insertIndex (pl-index.c:1807)
==8063==    by 0x12F2C7: hashDefinition (pl-index.c:1605)
==8063==    by 0x12CAA6: first_clause_guarded (pl-index.c:500)
==8063==    by 0x12CD6A: firstClause (pl-index.c:544)
==8063==    by 0x1B8C6D: pl_retract1_va (pl-proc.c:2556)
==8063==    by 0x154F1B: PL_next_solution (pl-vmi.c:3949)
==8063==    by 0x1B0B3B: query_loop (pl-pro.c:131)
==8063==    by 0x1B15B4: prologToplevel (pl-pro.c:466)
==8063==    by 0x20CCA4: PL_initialise (pl-init.c:1035)
==8063== 
==8063== 16 bytes in 1 blocks are definitely lost in loss record 16 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x2703B7: map_file (pl-zip.c:1136)
==8063==    by 0x2705D2: zip_open_archive (pl-zip.c:1259)
==8063==    by 0x20C5EB: openResourceDB (pl-init.c:852)
==8063==    by 0x20C8AC: PL_initialise (pl-init.c:938)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 16 bytes in 1 blocks are definitely lost in loss record 17 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x18243D: registerBuiltins (pl-ext.c:319)
==8063==    by 0x182739: initBuildIns (pl-ext.c:435)
==8063==    by 0x1D4B35: setupProlog (pl-setup.c:123)
==8063==    by 0x20C966: PL_initialise (pl-init.c:963)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 16 bytes in 1 blocks are definitely lost in loss record 18 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x182C04: initBuildIns (pl-ext.c:477)
==8063==    by 0x1D4B35: setupProlog (pl-setup.c:123)
==8063==    by 0x20C966: PL_initialise (pl-init.c:963)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 16 bytes in 1 blocks are definitely lost in loss record 19 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x17261E: lookupBodyProcedure (pl-comp.c:2527)
==8063==    by 0x172F65: compileSubClause (pl-comp.c:2722)
==8063==    by 0x170DD9: compileBody (pl-comp.c:2085)
==8063==    by 0x170870: compileBody (pl-comp.c:2032)
==8063==    by 0x16F69E: compileBody (pl-comp.c:1903)
==8063==    by 0x16EEDB: compileClause (pl-comp.c:1710)
==8063==    by 0x177547: assert_term (pl-comp.c:3663)
==8063==    by 0x177D41: record_clause (pl-comp.c:3861)
==8063== 
==8063== 16 bytes in 1 blocks are definitely lost in loss record 20 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x17261E: lookupBodyProcedure (pl-comp.c:2527)
==8063==    by 0x172F65: compileSubClause (pl-comp.c:2722)
==8063==    by 0x170DD9: compileBody (pl-comp.c:2085)
==8063==    by 0x16FBFE: compileBody (pl-comp.c:1940)
==8063==    by 0x16EEDB: compileClause (pl-comp.c:1710)
==8063==    by 0x177547: assert_term (pl-comp.c:3663)
==8063==    by 0x177D41: record_clause (pl-comp.c:3861)
==8063==    by 0x177DD1: pl_record_clause3_va (pl-comp.c:3876)
==8063== 
==8063== 16 bytes in 1 blocks are definitely lost in loss record 21 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x17261E: lookupBodyProcedure (pl-comp.c:2527)
==8063==    by 0x172F65: compileSubClause (pl-comp.c:2722)
==8063==    by 0x170DD9: compileBody (pl-comp.c:2085)
==8063==    by 0x17009D: compileBody (pl-comp.c:1966)
==8063==    by 0x16F69E: compileBody (pl-comp.c:1903)
==8063==    by 0x16EEDB: compileClause (pl-comp.c:1710)
==8063==    by 0x177547: assert_term (pl-comp.c:3663)
==8063==    by 0x177D41: record_clause (pl-comp.c:3861)
==8063== 
==8063== 16 bytes in 1 blocks are definitely lost in loss record 22 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x17261E: lookupBodyProcedure (pl-comp.c:2527)
==8063==    by 0x172F65: compileSubClause (pl-comp.c:2722)
==8063==    by 0x170DD9: compileBody (pl-comp.c:2085)
==8063==    by 0x16F69E: compileBody (pl-comp.c:1903)
==8063==    by 0x170255: compileBody (pl-comp.c:1975)
==8063==    by 0x16F69E: compileBody (pl-comp.c:1903)
==8063==    by 0x16EEDB: compileClause (pl-comp.c:1710)
==8063==    by 0x177547: assert_term (pl-comp.c:3663)
==8063== 
==8063== 16 bytes in 2 blocks are definitely lost in loss record 23 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x1B2D39: lookupProcedure (pl-proc.c:95)
==8063==    by 0x18243D: registerBuiltins (pl-ext.c:319)
==8063==    by 0x182799: initBuildIns (pl-ext.c:453)
==8063==    by 0x1D4B35: setupProlog (pl-setup.c:123)
==8063==    by 0x20C966: PL_initialise (pl-init.c:963)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 

[...]


==8063== 
==8063== 81,471 bytes in 1 blocks are still reachable in loss record 235 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x12B896: PL_malloc_atomic (pl-alloc.c:1202)
==8063==    by 0x16B04C: initWamTable (pl-comp.c:145)
==8063==    by 0x1D4939: setupProlog (pl-setup.c:86)
==8063==    by 0x20C966: PL_initialise (pl-init.c:963)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 146,680 bytes in 589 blocks are indirectly lost in loss record 236 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x12B896: PL_malloc_atomic (pl-alloc.c:1202)
==8063==    by 0x1E638B: loadPredicate (pl-wic.c:1533)
==8063==    by 0x1E3FA7: loadStatement (pl-wic.c:1025)
==8063==    by 0x1E7302: loadPart (pl-wic.c:1829)
==8063==    by 0x1E424A: loadStatement (pl-wic.c:1087)
==8063==    by 0x1E3F34: loadWicFd (pl-wic.c:1011)
==8063==    by 0x1E3CC6: loadWicFromStream (pl-wic.c:955)
==8063==    by 0x20CB84: PL_initialise (pl-init.c:1006)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 187,624 bytes in 1,473 blocks are indirectly lost in loss record 237 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x12B896: PL_malloc_atomic (pl-alloc.c:1202)
==8063==    by 0x16F0E5: compileClause (pl-comp.c:1749)
==8063==    by 0x177547: assert_term (pl-comp.c:3663)
==8063==    by 0x1779CE: pl_assertz11_va (pl-comp.c:3777)
==8063==    by 0x154461: PL_next_solution (pl-vmi.c:3747)
==8063==    by 0x1B1344: callProlog (pl-pro.c:368)
==8063==    by 0x22DDE0: pl_with_mutex (pl-mutex.c:743)
==8063==    by 0x154574: PL_next_solution (pl-vmi.c:3781)
==8063==    by 0x1B1344: callProlog (pl-pro.c:368)
==8063==    by 0x1B0F16: pl_notrace1_va (pl-pro.c:250)
==8063==    by 0x154461: PL_next_solution (pl-vmi.c:3747)
==8063== 
==8063== 470,296 bytes in 1,754 blocks are indirectly lost in loss record 238 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x12B896: PL_malloc_atomic (pl-alloc.c:1202)
==8063==    by 0x1E638B: loadPredicate (pl-wic.c:1533)
==8063==    by 0x1E3FA7: loadStatement (pl-wic.c:1025)
==8063==    by 0x1E7302: loadPart (pl-wic.c:1829)
==8063==    by 0x1E424A: loadStatement (pl-wic.c:1087)
==8063==    by 0x1E7302: loadPart (pl-wic.c:1829)
==8063==    by 0x1E424A: loadStatement (pl-wic.c:1087)
==8063==    by 0x1E7302: loadPart (pl-wic.c:1829)
==8063==    by 0x1E424A: loadStatement (pl-wic.c:1087)
==8063==    by 0x1E3F34: loadWicFd (pl-wic.c:1011)
==8063==    by 0x1E3CC6: loadWicFromStream (pl-wic.c:955)
==8063== 
==8063== 750,152 bytes in 1,927 blocks are indirectly lost in loss record 239 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x12B896: PL_malloc_atomic (pl-alloc.c:1202)
==8063==    by 0x16F0E5: compileClause (pl-comp.c:1749)
==8063==    by 0x177547: assert_term (pl-comp.c:3663)
==8063==    by 0x177D41: record_clause (pl-comp.c:3861)
==8063==    by 0x177DD1: pl_record_clause3_va (pl-comp.c:3876)
==8063==    by 0x154461: PL_next_solution (pl-vmi.c:3747)
==8063==    by 0x1B0B3B: query_loop (pl-pro.c:131)
==8063==    by 0x1B15B4: prologToplevel (pl-pro.c:466)
==8063==    by 0x20CCA4: PL_initialise (pl-init.c:1035)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== 2,136,176 (32 direct, 2,136,144 indirect) bytes in 1 blocks are definitely lost in loss record 240 of 240
==8063==    at 0x483777F: malloc (vg_replace_malloc.c:299)
==8063==    by 0x129351: allocHeap (pl-alloc.c:146)
==8063==    by 0x12937A: allocHeapOrHalt (pl-alloc.c:160)
==8063==    by 0x24DA51: newHTable (pl-table.c:483)
==8063==    by 0x18259A: initBuildIns (pl-ext.c:400)
==8063==    by 0x1D4B35: setupProlog (pl-setup.c:123)
==8063==    by 0x20C966: PL_initialise (pl-init.c:963)
==8063==    by 0x128558: main (pl-main.c:113)
==8063== 
==8063== LEAK SUMMARY:
==8063==    definitely lost: 94,368 bytes in 780 blocks
==8063==    indirectly lost: 2,145,355 bytes in 18,660 blocks
==8063==      possibly lost: 272 bytes in 1 blocks
==8063==    still reachable: 83,887 bytes in 26 blocks
==8063==         suppressed: 0 bytes in 0 blocks
==8063== 
==8063== For counts of detected and suppressed errors, rerun with: -v
==8063== ERROR SUMMARY: 75 errors from 75 contexts (suppressed: 0 from 0)


#2

Most of the global data is not reclaimed. If you compile in debug mode it does a little more of that, but I never bothered making the cleanup complete. Complicated and not very useful.