]> granicus.if.org Git - json-c/commitdiff
* Fix file descriptor leak if memory allocation fails in json_util
authorMichael Clark <michael@metaparadigm.com>
Wed, 13 Oct 2010 14:10:51 +0000 (14:10 +0000)
committerMichael Clark <michael@metaparadigm.com>
Wed, 13 Oct 2010 14:10:51 +0000 (14:10 +0000)
    Zachary Blair, zack_blair at hotmail dot com

git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@59 327403b1-1117-474d-bef2-5cb71233fd97

json_util.c

index 203a70fa0abb5a19f03e892b3d2d34300a81b73a..0dcd6d50cf05a67346afe72f6092ec8e9593dc51 100644 (file)
@@ -103,8 +103,10 @@ int json_object_to_file(char *filename, struct json_object *obj)
     return -1;
   }
 
-  if(!(json_str = json_object_to_json_string(obj))) { return -1; }
-
+  if(!(json_str = json_object_to_json_string(obj))) {
+    close(fd);
+    return -1;
+  }
 
   wsize = (unsigned int)(strlen(json_str) & UINT_MAX); /* CAW: probably unnecessary, but the most 64bit safe */
   wpos = 0;