Fix warning about object being leaked from update installer thread due to a missing autorelease pool

Allocate an NSAutoreleasePool in the updater thread and release it just
before the thread exits.
This commit is contained in:
Robert Knight 2011-08-23 16:30:17 +01:00
parent ff21b77ec1
commit 214f2273b9
3 changed files with 23 additions and 0 deletions

View file

@ -19,6 +19,9 @@ class UpdateDialogCocoa : public UpdateObserver
virtual void updateProgress(int percentage);
virtual void updateFinished();
static void* createAutoreleasePool();
static void releaseAutoreleasePool(void* data);
private:
UpdateDialogPrivate* d;
};

View file

@ -137,4 +137,14 @@ void UpdateDialogCocoa::updateFinished()
waitUntilDone:false];
}
void* UpdateDialogCocoa::createAutoreleasePool()
{
return [[NSAutoreleasePool alloc] init];
}
void UpdateDialogCocoa::releaseAutoreleasePool(void* arg)
{
[(id)arg release];
}

View file

@ -20,6 +20,12 @@ void runWithUi(int argc, char** argv, UpdateInstaller* installer);
void runUpdaterThread(void* arg)
{
#ifdef PLATFORM_MAC
// create an autorelease pool to free any temporary objects
// created by Cocoa whilst handling notifications from the UpdateInstaller
void* pool = UpdateDialogCocoa::createAutoreleasePool();
#endif
try
{
UpdateInstaller* installer = static_cast<UpdateInstaller*>(arg);
@ -29,6 +35,10 @@ void runUpdaterThread(void* arg)
{
LOG(Error,"Unexpected exception " + std::string(ex.what()));
}
#ifdef PLATFORM_MAC
UpdateDialogCocoa::releaseAutoreleasePool(pool);
#endif
}
int main(int argc, char** argv)