diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-12-22 17:00:00 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-12-22 17:00:00 +0100 |
commit | f6e8b115d49e8aec463e3a495d53ee11031a4db6 (patch) | |
tree | d9c2474f8bc88861dcfd33a89cbe3e5e6420c7e9 /sys | |
parent | 9b0de7f9d63386bc5e2cb5889559bbdb0c11503d (diff) |
libjson: fix memory leak setjmp/longjmp problem (thanks spew)
spew → I fixed the memory leak setjmp/longjmp problem with libjson
spew → http://www.spew.club/json.patch
spew → full file: http://www.spew.club/json.c
spew → going to bed, I'll annoy cinap_lenrek tomorrow to try to get this committed
Diffstat (limited to 'sys')
-rw-r--r-- | sys/src/libjson/json.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/sys/src/libjson/json.c b/sys/src/libjson/json.c index 4a671c4e5..c62cfa248 100644 --- a/sys/src/libjson/json.c +++ b/sys/src/libjson/json.c @@ -22,8 +22,6 @@ struct Lex double n; char *buf; Rune peeked; - jmp_buf jmp; - int canjmp; }; static Rune @@ -50,6 +48,20 @@ peekch(Lex *l) return l->peeked; } +static Rune +peeknonspace(Lex *l) +{ + Rune r; + + for(;;){ + r = peekch(l); + if(r != 0x20 && r != 0x09 && r != 0x0A && r != 0x0D) + break; + getch(l); + } + return r; +} + static int fixsurrogate(Rune *rp, Rune r2) { @@ -81,16 +93,8 @@ lex(Lex *l) int i; char c; - for(;;){ - r = peekch(l); - if(r != 0x20 && r != 0x09 && r != 0x0A && r != 0x0D) - break; - getch(l); - } + peeknonspace(l); r = getch(l); - if(r == ']' && l->canjmp) - longjmp(l->jmp, 1); - l->canjmp = 0; if(r == 0 || r == '{' || r == '[' || r == ']' || r == '}' || r == ':' || r == ','){ l->t = r; return 0; @@ -241,7 +245,6 @@ error: case '[': obj = l->t == '{'; ln = &j->first; - e = nil; if(obj){ j->t = JSONObject; if(lex(l) < 0) @@ -251,9 +254,8 @@ error: goto firstobj; }else{ j->t = JSONArray; - l->canjmp = 1; - if(setjmp(l->jmp) > 0){ - free(e); + if(peeknonspace(l) == ']'){ + getch(l); return j; } } |