Page 1 of 1

Patch to fix pbzx memory leaks

PostPosted: Mon Feb 05, 2018 12:46 am
by ryandesign
Thank you for writing the pbzx tool. Using the version from 20170731 posted in your OTA: Episode V : XZ strikes back post, I noticed that while decompressing the pbzx stream inside Xcode_9.2.xip, the pbzx program's memory usage kept growing up to 11GB. After applying this patch, memory usage stayed around 20-30MB.

Code: Select all
Fix memory leaks.
--- 02_decompress.c.orig   2017-07-31 11:26:22.000000000 -0500
+++ 02_decompress.c   2018-02-04 01:32:19.000000000 -0600
@@ -378,6 +378,7 @@
 
    decompressBytes(&strm, buf, size);
 
+   lzma_end(&strm);
 
 
 }
--- pbzx.c.orig   2017-07-31 11:25:52.000000000 -0500
+++ pbzx.c   2018-02-04 01:22:14.000000000 -0600
@@ -120,6 +120,7 @@
    warn = 0;
 
    }
+   free(buf);
     }
 
     return 0;

Re: Patch to fix pbzx memory leaks

PostPosted: Mon Feb 05, 2018 2:31 am
by morpheus
Thanks for the fix! I never really thought about freeing memory because pbzx and Ota execute for a very short time and exit - but every improvement helps !

Re: Patch to fix pbzx memory leaks

PostPosted: Thu Mar 15, 2018 5:40 pm
by ryandesign
I see that you released a new version of pbzx.c on March 10, 2018, but it does not contain this fix. Could you release a new version of pbzx.c and 02_decompress.c containing these fixes? The difference between using 30MB of memory and using 11GB of memory is pretty significant.

J says: Ooops. Forgot that. Added in sources.