aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-05-10 21:49:25 +0930
committerMark Pulford <mark@kyne.com.au>2011-05-10 21:49:25 +0930
commita472725b6db0132e06a063f2f67c8a04bf910c60 (patch)
tree075f4cc3e3bff557df1f4247edfd735e886e790c
parent2123c622de3a527b6173f6826bf8ceb21ed840fd (diff)
downloadlua-cjson-a472725b6db0132e06a063f2f67c8a04bf910c60.tar.gz
lua-cjson-a472725b6db0132e06a063f2f67c8a04bf910c60.tar.bz2
lua-cjson-a472725b6db0132e06a063f2f67c8a04bf910c60.zip
Fix memory leak when throwing stack overflow error
json->tmp was not freed when throwing a Lua stack overflow exception.
-rw-r--r--lua_cjson.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/lua_cjson.c b/lua_cjson.c
index 63b3d06..f888644 100644
--- a/lua_cjson.c
+++ b/lua_cjson.c
@@ -1017,13 +1017,22 @@ static void json_throw_parse_error(lua_State *l, json_parse_t *json,
1017 exp, found, token->index + 1); 1017 exp, found, token->index + 1);
1018} 1018}
1019 1019
1020static void json_decode_checkstack(lua_State *l, json_parse_t *json, int n)
1021{
1022 if (lua_checkstack(l, n))
1023 return;
1024
1025 strbuf_free(json->tmp);
1026 luaL_error(l, "Too many nested data structures");
1027}
1028
1020static void json_parse_object_context(lua_State *l, json_parse_t *json) 1029static void json_parse_object_context(lua_State *l, json_parse_t *json)
1021{ 1030{
1022 json_token_t token; 1031 json_token_t token;
1023 1032
1024 /* 3 slots required: 1033 /* 3 slots required:
1025 * .., table, key, value */ 1034 * .., table, key, value */
1026 luaL_checkstack(l, 3, "too many nested data structures"); 1035 json_decode_checkstack(l, json, 3);
1027 1036
1028 lua_newtable(l); 1037 lua_newtable(l);
1029 1038
@@ -1072,7 +1081,7 @@ static void json_parse_array_context(lua_State *l, json_parse_t *json)
1072 1081
1073 /* 2 slots required: 1082 /* 2 slots required:
1074 * .., table, value */ 1083 * .., table, value */
1075 luaL_checkstack(l, 2, "too many nested data structures"); 1084 json_decode_checkstack(l, json, 2);
1076 1085
1077 lua_newtable(l); 1086 lua_newtable(l);
1078 1087