tst_qstring_mac: Correct memory management.
authorMorten Johan Sørvig <morten.sorvig@digia.com>
Tue, 13 Jan 2015 09:49:07 +0000 (10:49 +0100)
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>
Tue, 20 Jan 2015 04:47:16 +0000 (05:47 +0100)
The NSStrings return by QString::toNSString are autoreleased;
manually releasing them is not correct. The test still
works (no leaks or double deletes) since there is no
autorelease pool in place when running it.

We don't want to encourage incorrect usage: remove
the release call an add an autorelease pool.

Change-Id: Ic566fd3a8efd6cbc0eb6db850248a68bfc8fed0b
Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
tests/auto/corelib/tools/qstring/tst_qstring_mac.mm

index 9061b6c39d4b58135543505b212cdc1ea12618b2..4cec5b3798f4493f0df61c8d3bc0b60c5d446c3d 100644 (file)
@@ -63,17 +63,23 @@ void tst_QString_macTypes()
     }
     // QString <-> NSString
     {
+        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
         QString qtString("test string");
         const NSString *nsString = qtString.toNSString();
         QCOMPARE(QString::fromNSString(nsString), qtString);
-        [nsString release];
+
+        [pool release];
     }
     {
+        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
         QString qtString("test string");
         const NSString *nsString = qtString.toNSString();
         QString qtStringCopy(qtString);
         qtString = qtString.toUpper(); // modify
         QCOMPARE(QString::fromNSString(nsString), qtStringCopy);
-        [nsString release];
+
+        [pool release];
     }
 }