Permalink
Browse files

* Fix file descriptor leak if memory allocation fails in json_util

    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
  • Loading branch information...
1 parent bd0a567 commit f1ae67dbf0d5d921d2786cc63878dcc21e2a32ea @michaeljclark michaeljclark committed Oct 13, 2010
Showing with 4 additions and 2 deletions.
  1. +4 −2 json_util.c
View
@@ -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;

0 comments on commit f1ae67d

Please sign in to comment.