purplecabbage closed pull request #351: Prevent a memory leak when converting 
to JSON
URL: https://github.com/apache/cordova-ios/pull/351
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/CordovaLib/Classes/Private/CDVJSON_private.m 
b/CordovaLib/Classes/Private/CDVJSON_private.m
index 054d655de..175ed3984 100644
--- a/CordovaLib/Classes/Private/CDVJSON_private.m
+++ b/CordovaLib/Classes/Private/CDVJSON_private.m
@@ -24,16 +24,18 @@ @implementation NSArray (CDVJSONSerializingPrivate)
 
 - (NSString*)cdv_JSONString
 {
-    NSError* error = nil;
-    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self
-                                                       options:0
-                                                         error:&error];
-
-    if (error != nil) {
-        NSLog(@"NSArray JSONString error: %@", [error localizedDescription]);
-        return nil;
-    } else {
-        return [[NSString alloc] initWithData:jsonData 
encoding:NSUTF8StringEncoding];
+    @autoreleasepool {
+        NSError* error = nil;
+        NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self
+                                                           options:0
+                                                             error:&error];
+
+        if (error != nil) {
+            NSLog(@"NSArray JSONString error: %@", [error 
localizedDescription]);
+            return nil;
+        } else {
+            return [[NSString alloc] initWithData:jsonData 
encoding:NSUTF8StringEncoding];
+        }
     }
 }
 
@@ -43,16 +45,18 @@ @implementation NSDictionary (CDVJSONSerializingPrivate)
 
 - (NSString*)cdv_JSONString
 {
-    NSError* error = nil;
-    NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self
-                                                       
options:NSJSONWritingPrettyPrinted
-                                                         error:&error];
-
-    if (error != nil) {
-        NSLog(@"NSDictionary JSONString error: %@", [error 
localizedDescription]);
-        return nil;
-    } else {
-        return [[NSString alloc] initWithData:jsonData 
encoding:NSUTF8StringEncoding];
+    @autoreleasepool {
+        NSError* error = nil;
+        NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self
+                                                           
options:NSJSONWritingPrettyPrinted
+                                                             error:&error];
+
+        if (error != nil) {
+            NSLog(@"NSDictionary JSONString error: %@", [error 
localizedDescription]);
+            return nil;
+        } else {
+            return [[NSString alloc] initWithData:jsonData 
encoding:NSUTF8StringEncoding];
+        }
     }
 }
 
@@ -62,30 +66,34 @@ @implementation NSString (CDVJSONSerializingPrivate)
 
 - (id)cdv_JSONObject
 {
-    NSError* error = nil;
-    id object = [NSJSONSerialization JSONObjectWithData:[self 
dataUsingEncoding:NSUTF8StringEncoding]
-                                                
options:NSJSONReadingMutableContainers
-                                                  error:&error];
-    
-    if (error != nil) {
-        NSLog(@"NSString JSONObject error: %@, Malformed Data: %@", [error 
localizedDescription], self);
-    }
+    @autoreleasepool {   
+        NSError* error = nil;
+        id object = [NSJSONSerialization JSONObjectWithData:[self 
dataUsingEncoding:NSUTF8StringEncoding]
+                                                    
options:NSJSONReadingMutableContainers
+                                                      error:&error];
+
+        if (error != nil) {
+            NSLog(@"NSString JSONObject error: %@, Malformed Data: %@", [error 
localizedDescription], self);
+        }
 
-    return object;
+        return object;
+    }
 }
 
 - (id)cdv_JSONFragment
 {
-    NSError* error = nil;
-    id object = [NSJSONSerialization JSONObjectWithData:[self 
dataUsingEncoding:NSUTF8StringEncoding]
-                                                
options:NSJSONReadingAllowFragments
-                                                  error:&error];
+    @autoreleasepool {
+        NSError* error = nil;
+        id object = [NSJSONSerialization JSONObjectWithData:[self 
dataUsingEncoding:NSUTF8StringEncoding]
+                                                    
options:NSJSONReadingAllowFragments
+                                                      error:&error];
 
-    if (error != nil) {
-        NSLog(@"NSString JSONObject error: %@", [error localizedDescription]);
-    }
+        if (error != nil) {
+            NSLog(@"NSString JSONObject error: %@", [error 
localizedDescription]);
+        }
 
-    return object;
+        return object;
+    }
 }
 
 @end


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to