Reputation: 1448
I'm gratefully using the ZipArchive library but it seems there is a memory leak. I don't know how to fix this - it's written in C and I'm unfamiliar with it. My question is - is it possible to autorelease the line s=(unz_s*)ALLOC(sizeof(unz_s)); like you would in Objective-C in this scenario?
extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
const char *path;
zlib_filefunc_def* pzlib_filefunc_def;
{
// ...
s=(unz_s*)ALLOC(sizeof(unz_s));
*s=us;
unzGoToFirstFile((unzFile)s);
return (unzFile)s;
}
Here is a screen grab of the location of the leak for clarity:
Can anybody could shed some light on how I might fix this? Thanks.
Upvotes: 0
Views: 690
Reputation: 628
i have faced the same problem and Solved by reading some of the blogs . it seems to simple
close your ZipArchive Object before relesing Object
its look like [ZipObj UnzipCloseFile];
Upvotes: 2
Reputation: 243156
No, you cannot autorelease it. Autoreleasing is only available for Objective-C objects. So you have 2 options:
free()
.s
thing into an NSData
using dataWithBytesNoCopy:length:
, which will take ownership of the allocated data and free it when the NSData
object is deallocated.Option 2 would look something like this:
unz_s * s = unzOpen2(...);
NSData * boxedS = [NSData dataWithBytesNoCopy:s length:sizeof(unz_s)];
Then when boxedS
gets destroyed, it will free s
as well.
Upvotes: 0