Reimplementation of Pijul in C, for education, fun and absolutely no profit

#8 Investigate and fix resource leaks

Closed on July 18, 2023
laumann on July 17, 2023

We haven’t been too careful about resource management after change() is done - we should ensure that all resources are properly released, both on success and failure.

laumann on July 17, 2023

Valgrind run:

valgrind --leak-check=full build/ani change AGBLQOQIB6DSD2APO6L2PLFXF7CRWKAD6VAWIAD6F2DTH4EIRYRQC
==3651== Memcheck, a memory error detector
==3651== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==3651== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info
==3651== Command: build/ani change AGBLQOQIB6DSD2APO6L2PLFXF7CRWKAD6VAWIAD6F2DTH4EIRYRQC
==3651== 
message = contrib/pijul-status: print all-ok message when no changes detected
timestamp = '2022-09-27T12:12:18.246927153Z'

[[authors]]
key = 'AFgzZkD8ARgC21gkkCvxPV5HbL7YDVzgYEhbAxQG7UQY'

# Dependencies
 4DUOW3T334XG5GYSY4HTQJAZ2JCBAYUBHWLKJ7PKQXGVMA2WZFWQC
+5YTX4YURTNMDR6W725M6XZUEKYC7PCBUJAITEFT7KQKZ6RGJDYGQC

# Hunks

1. edit in contrib/pijul-status:42 (UTF-8)
- 

2. edit in contrib/pijul-status:47 (UTF-8)
up: P0.1486, new: 0:88, down: P0.1486
+ 			}
+ 			if (ci == 0 && ui == 0) {
+ 				printf("nothing to record, working copy clean\n")
==3651== 
==3651== HEAP SUMMARY:
==3651==     in use at exit: 7,603 bytes in 21 blocks
==3651==   total heap usage: 94 allocs, 73 frees, 29,732,931 bytes allocated
==3651== 
==3651== 26 bytes in 1 blocks are definitely lost in loss record 10 of 21
==3651==    at 0x48417E4: malloc (vg_replace_malloc.c:393)
==3651==    by 0x49D5C99: strdup (strdup.c:42)
==3651==    by 0x14032A: xstrdup (scaffold.c:71)
==3651==    by 0x140008: find_dotpijul (dir.c:59)
==3651==    by 0x115DDE: cmd_main (ani.c:74)
==3651==    by 0x115E4A: main (ani.c:87)
==3651== 
==3651== 7,577 (6,912 direct, 665 indirect) bytes in 1 blocks are definitely lost in loss record 21 of 21
==3651==    at 0x48417E4: malloc (vg_replace_malloc.c:393)
==3651==    by 0x140290: xmalloc (scaffold.c:49)
==3651==    by 0x118477: changestoreinit (change.c:912)
==3651==    by 0x118A32: change (change.c:1065)
==3651==    by 0x118E23: cmd_change (change.c:1156)
==3651==    by 0x115E18: cmd_main (ani.c:78)
==3651==    by 0x115E4A: main (ani.c:87)
==3651== 
==3651== LEAK SUMMARY:
==3651==    definitely lost: 6,938 bytes in 2 blocks
==3651==    indirectly lost: 665 bytes in 19 blocks
==3651==      possibly lost: 0 bytes in 0 blocks
==3651==    still reachable: 0 bytes in 0 blocks
==3651==         suppressed: 0 bytes in 0 blocks
==3651== 
==3651== For lists of detected and suppressed errors, rerun with: -s
==3651== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
laumann added a change on July 17, 2023
2OSIAH5Q7QO2OPW4T4J6MSECWTWH2MSV6VWIZW7N45DOWFFUJ6JQC
main
laumann added a change on July 17, 2023
CWII6DASI3JOJAA4PXSSVJOEUBT32KTGB3VZXKTUCFXK3KNRH2DAC
main
laumann added a change on July 18, 2023
UM5XFLGIZYSFAP6TFEZR4APDSSHRHZJDQKXPFGKT6LUAK7QXN33QC
main
laumann added a change on July 18, 2023
FM2KHERTELOSEZRVS6JVE4TWW2S75USLHXQSOIOYH5IQ4JECQIXQC
main
laumann on July 18, 2023

The command:

valgrind --leak-check=full build/ani change AGBLQOQIB6DSD2APO6L2PLFXF7CRWKAD6VAWIAD6F2DTH4EIRYRQC

now reports all allocated resources freed! Other tests also report all good, so closing this for now.

laumann closed this discussion on July 18, 2023