Feedback from my first Objective-C code (QuickLook plugin)

I wrote a fairly simple QuickLook plugin that displays .torrent file files,

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

The reason I'm looking for a review is a bit strange .. After creating / installing the plugin (in ~/Library/QuickLook/ ) and running it.

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

.. it works fine, but actually calls QuickLook (through a space or cmd+y shortcut), the first time is fine, then there are problems - strange characters after the data (similar to those resolved with this question ), or it goes back to The default is β€œshow file info and icon” quicklook plugin.

I assume this is a memory leak problem. I could be wrong, but the qlmanage command's memory should be "clean" (being a new process), but the quicklook daemon runs for a long time, which means that it will be spoiled by a leak.

I ran the Clang static analyzer in the code, and the only leaks that it found were in BEncoding.m .. I found it hard to believe that the library was to blame (not my dirty code), espically gave this answer , saying that <Tool t26 > is impractical with code collected with garbage (not sure if this applies to Clang?), so this question!

+1
source share
2 answers

First, Quick Look generators are not going to garbage collection. It seems that BEncoding can be written to collect garbage, as I have never seen it release anything.

Thus, leaks detected by the Clang static analyzer in BEncoding are also real. For example, in -[BEncoding encodedDataFromObject:] , data should be auto-implemented. The same goes for -[BEncoding dataFromEncodedData] - dataLength should also be auto-implemented.

However, it seems that errors that cause corrupted output may also be in BEncoding , and the Clang analyzer does not capture it in places. Just write a simple test shell that runs your code twice.

You might be better off just rewriting BEncoding yourself; it is not very long and may seem instructive. Using Cocoa objects like NSData rather than raw source memory buffers should help .:-)

+2
source

There is a QuickLook torrent generator that runs on technocrank.com

+1
source

Source: https://habr.com/ru/post/886423/


All Articles