Skip to content

Commit

Permalink
Fix memory leak in JsonParser
Browse files Browse the repository at this point in the history
Signed-off-by: Jiří Janoušek <janousek.jiri@gmail.com>
  • Loading branch information
jiri-janousek committed Dec 23, 2018
1 parent 0a88c41 commit 80ef765
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/glib/JsonParser.vala
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ public class JsonParser {
}

private void parse_object(out JsonObject object) throws JsonError {
object = new JsonObject();
object = null;
var new_object = new JsonObject();
/* Look for the end of the object */
skip_whitespace();
char c = peek_char();
Expand All @@ -345,6 +346,7 @@ public class JsonParser {
"%u:%u Unexpected end of data. A string or '}' expected.", line, column);
case '}':
get_char();
object = (owned) new_object;
return;
}
while (true) {
Expand Down Expand Up @@ -381,7 +383,7 @@ public class JsonParser {
/* Parse the value */
JsonNode node = null;
parse_one(out node);
object[key] = node;
new_object[key] = node;

/* Look for a comma or the end of the object */
skip_whitespace();
Expand All @@ -393,6 +395,7 @@ public class JsonParser {
case ',':
break;
case '}':
object = (owned) new_object;
return;
default:
throw new JsonError.PARSE_ERROR(
Expand All @@ -402,12 +405,13 @@ public class JsonParser {
}

private void parse_array(out JsonArray array) throws JsonError {
array = null;
if (++array_recursion >= 20) {
throw new JsonError.PARSE_ERROR(
"%u:%u Maximal array recursion depth reached.", line, column);
}

array = new JsonArray();
var new_array = new JsonArray();
/* Look for the end of the array */
skip_whitespace();
switch (peek_char()) {
Expand All @@ -417,6 +421,7 @@ public class JsonParser {
case ']':
get_char();
array_recursion--;
array = (owned) new_array;
return;
}
while (true) {
Expand All @@ -430,7 +435,7 @@ public class JsonParser {
/* Parse the value */
JsonNode node;
parse_one(out node);
array.append(node);
new_array.append(node);
break;
}

Expand All @@ -445,6 +450,7 @@ public class JsonParser {
break;
case ']':
array_recursion--;
array = (owned) new_array;
return;
default:
throw new JsonError.PARSE_ERROR(
Expand Down

0 comments on commit 80ef765

Please sign in to comment.