Static Analyzer: WebCoreNSURLExtras.mm: Potential leak of memory pointed to by 'allBy...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Feb 2017 06:23:41 +0000 (06:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 5 Feb 2017 06:23:41 +0000 (06:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167849

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2017-02-04
Reviewed by Sam Weinig.

Source/WebCore/platform/mac/WebCoreNSURLExtras.mm:883:20: warning: Potential leak of memory pointed to by 'allBytesBuffer'
            return nil;
                   ^~~

* platform/mac/WebCoreNSURLExtras.mm:
(WebCore::dataForURLComponentType):
Free the potentially malloc'd buffer before the early return.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/WebCoreNSURLExtras.mm

index 95768a5..5a13e7f 100644 (file)
@@ -1,3 +1,18 @@
+2017-02-04  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Static Analyzer: WebCoreNSURLExtras.mm: Potential leak of memory pointed to by 'allBytesBuffer'
+        https://bugs.webkit.org/show_bug.cgi?id=167849
+
+        Reviewed by Sam Weinig.
+
+        Source/WebCore/platform/mac/WebCoreNSURLExtras.mm:883:20: warning: Potential leak of memory pointed to by 'allBytesBuffer'
+                    return nil;
+                           ^~~
+
+        * platform/mac/WebCoreNSURLExtras.mm:
+        (WebCore::dataForURLComponentType):
+        Free the potentially malloc'd buffer before the early return.
+
 2017-02-04  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed, fix mistake in comment added in r211569.
index 2bdc6be..b2b3525 100644 (file)
@@ -879,8 +879,11 @@ NSData *dataForURLComponentType(NSURL *URL, CFURLComponentType componentType)
     CFRange range;
     if (componentType != completeURL) {
         range = CFURLGetByteRangeForComponent((CFURLRef)URL, componentType, NULL);
-        if (range.location == kCFNotFound)
+        if (range.location == kCFNotFound) {
+            if (staticAllBytesBuffer != allBytesBuffer)
+                free(allBytesBuffer);
             return nil;
+        }
     } else {
         range.location = 0;
         range.length = bytesFilled;