From: Michael Clark Date: Wed, 13 Oct 2010 14:10:51 +0000 (+0000) Subject: * Fix file descriptor leak if memory allocation fails in json_util X-Git-Tag: json-c-0.10-20120530~60 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=f1ae67dbf0d5d921d2786cc63878dcc21e2a32ea;p=thirdparty%2Fjson-c.git * 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 --- diff --git a/json_util.c b/json_util.c index 203a70fa..0dcd6d50 100644 --- a/json_util.c +++ b/json_util.c @@ -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;