diff options
author | BurnZeZ <brz-9dev@intma.in> | 2013-10-28 03:17:53 -0400 |
---|---|---|
committer | BurnZeZ <brz-9dev@intma.in> | 2013-10-28 03:17:53 -0400 |
commit | 96c1e08f481b67ea0e8694931cd7e46d339f5fc5 (patch) | |
tree | baf53f743cf23e08c5b6a3d5f6d269087fcd60d8 /sys/src/libjson | |
parent | a8e8b650f3643c1a9f434fb2efb4708ff53539cd (diff) |
libjson: fix missing buffer free, slight cleanup
Diffstat (limited to 'sys/src/libjson')
-rw-r--r-- | sys/src/libjson/json.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/sys/src/libjson/json.c b/sys/src/libjson/json.c index 1cf77be3b..8186976a3 100644 --- a/sys/src/libjson/json.c +++ b/sys/src/libjson/json.c @@ -203,13 +203,9 @@ jsonobj(Lex *l) JSONEl **ln; int obj; - l->buf = mallocz(l->slen, 1); - if(l->buf == nil) + if((j = mallocz(sizeof(*j), 1)) == nil) return nil; - j = mallocz(sizeof(*j), 1); - if(j == nil) - return nil; if(lex(l) < 0){ error: free(j); @@ -232,8 +228,7 @@ error: break; case TSTRING: j->t = JSONString; - j->s = strdup(l->buf); - if(j->s == nil) + if((j->s = strdup(l->buf)) == nil) goto error; break; case TNUM: @@ -269,8 +264,7 @@ error: werrstr("json: syntax error, not string"); goto abort; } - e = mallocz(sizeof(*e), 1); - if(e == nil) + if((e = mallocz(sizeof(*e), 1)) == nil) goto abort; e->name = strdup(l->buf); if(e->name == nil || lex(l) < 0){ @@ -283,8 +277,7 @@ error: goto abort; } }else{ - e = mallocz(sizeof(*e), 1); - if(e == nil) + if((e = mallocz(sizeof(*e), 1)) == nil) goto abort; } e->val = jsonobj(l); @@ -320,12 +313,18 @@ error: JSON* jsonparse(char *s) { + JSON *j; Lex l; memset(&l, 0, sizeof(l)); l.s = s; l.slen = strlen(s)+1; - return jsonobj(&l); + if((l.buf = mallocz(l.slen, 1)) == nil) + return nil; + + j = jsonobj(&l); + free(l.buf); + return j; } void |