-[JSContext setName:] leaks NSString
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jun 2014 21:41:44 +0000 (21:41 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jun 2014 21:41:44 +0000 (21:41 +0000)
<http://webkit.org/b/134038>

Reviewed by Joseph Pecoraro.

Fixes the following static analyzer warning:

    JavaScriptCore/API/JSContext.mm:200:73: warning: Potential leak of an object
        JSStringRef nameJS = name ? JSStringCreateWithCFString((CFStringRef)[name copy]) : nullptr;
                                                                            ^

* API/JSContext.mm:
(-[JSContext setName:]): Autorelease the copy of |name|.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170117 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/API/JSContext.mm
Source/JavaScriptCore/ChangeLog

index c8f4d4c52b9b9dc30cec650f9693e06fbee7d295..ef59fef72073bab060ee3a772af9dec85780959c 100644 (file)
 
 - (void)setName:(NSString *)name
 {
-    JSStringRef nameJS = name ? JSStringCreateWithCFString((CFStringRef)[name copy]) : nullptr;
+    JSStringRef nameJS = name ? JSStringCreateWithCFString((CFStringRef)[[name copy] autorelease]) : nullptr;
     JSGlobalContextSetName(m_context, nameJS);
     if (nameJS)
         JSStringRelease(nameJS);
index addd7434c0799febf316bd921c5cfd5a7ee206d9..a2af5e5065b679afe5a99ed2a6900715ff9cbe56 100644 (file)
@@ -1,3 +1,19 @@
+2014-06-18  David Kilzer  <ddkilzer@apple.com>
+
+        -[JSContext setName:] leaks NSString
+        <http://webkit.org/b/134038>
+
+        Reviewed by Joseph Pecoraro.
+
+        Fixes the following static analyzer warning:
+
+            JavaScriptCore/API/JSContext.mm:200:73: warning: Potential leak of an object
+                JSStringRef nameJS = name ? JSStringCreateWithCFString((CFStringRef)[name copy]) : nullptr;
+                                                                                    ^
+
+        * API/JSContext.mm:
+        (-[JSContext setName:]): Autorelease the copy of |name|.
+
 2014-06-18  Mark Lam  <mark.lam@apple.com>
 
         DFGGraph::m_doubleConstantMap will not map 0 values correctly.