views:

381

answers:

2

I've written a fairly simply QuickLook plugin, which displays the files of a .torrent file,

The complete code is here on Github, and the main file is torrent.m

The reason I'm looking for feedback is it's acting slightly weirdly.. After building/installing the plugin (into ~/Library/QuickLook/), and running..

qlmanage -r; qlmanage -p ~/test.torrent

..it works perfectly, but actually invoking QuickLook (via the "space" or cmd+y shortcut), the first time is fine, then there are problems - strange characters after the data (similar to the solved with this question), or it falls back to the default "show file info and icon" quicklook plugin.

I'm assuming it's a memory-leak related problem.. I could be wrong, but the qlmanage command's memory should be "clean" (being a new process), but the quicklook daemon is long running, meaning it would be messed up by the leak..

I ran the Clang static analyser on the code, and the only leaks it found were in the BEncoding.m.. I found it hard to believe the library was at fault (not my messy code), espically given this answer saying the leak tool is innacurate with garbage-collected code (not sure if this applies to Clang?), thus this question!

+2  A: 

First, Quick Look generators don't get compiled with garbage collection on. It looks like BEncoding may have been written to assume garbage collection, as I don't ever see it release anything.

As such, the leaks the Clang static analyzer finds in BEncoding are real as well. For example, in -[BEncoding encodedDataFromObject:], data should be autoreleased. Same for -[BEncoding dataFromEncodedData]dataLength should be autoreleased as well.

However, it looks like the bugs causing corrupted output may also be in BEncoding, and in places the Clang analyzer isn't catching. Just write a simple test wrapper that runs your code twice.

You might be better off just rewriting BEncoding yourself; it's not very long and may prove instructive. Using Cocoa objects such as NSData rather than unchecked raw memory buffers should help. :-)

Nicholas Riley
Ahh, that makes sense. Thanks!
dbr
+1  A: 

There's a QuickLook torrent generator that works at technocrank.com

Great, thanks! It's a shame it's not open-source, but oh well..
dbr