aboutsummaryrefslogtreecommitdiffstats
path: root/src/n3.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-05-08 15:27:32 -0400
committerDavid Robillard <d@drobilla.net>2022-06-10 10:36:59 -0400
commitf6437f606bd85dbc6d7581146955f85902230ca0 (patch)
tree29526f43272a8c13455379f4f34b0580af0aa729 /src/n3.c
parent272d7081257dc6d50c06b1b62e8c4baa5bf3b4b2 (diff)
downloadserd-f6437f606bd85dbc6d7581146955f85902230ca0.tar.gz
serd-f6437f606bd85dbc6d7581146955f85902230ca0.tar.bz2
serd-f6437f606bd85dbc6d7581146955f85902230ca0.zip
Fix memory consumption when reading documents
Diffstat (limited to 'src/n3.c')
-rw-r--r--src/n3.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/n3.c b/src/n3.c
index 33828258..60d975c2 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -1572,7 +1572,7 @@ read_wrappedGraph(SerdReader* const reader, ReadContext* const ctx)
reader, SERD_ERR_BAD_SYNTAX, "missing predicate object list\n");
}
- pop_node(reader, ctx->subject);
+ ctx->subject = pop_node(reader, ctx->subject);
read_ws_star(reader);
if (peek_byte(reader) == '.') {
eat_byte_safe(reader, '.');
@@ -1606,6 +1606,10 @@ tokcmp(SerdReader* const reader,
SerdStatus
read_n3_statement(SerdReader* const reader)
{
+#ifndef NDEBUG
+ const size_t orig_stack_size = reader->stack.size;
+#endif
+
SerdStatementFlags flags = 0;
ReadContext ctx = {0, 0, 0, 0, 0, 0, &flags};
bool ate_dot = false;
@@ -1646,6 +1650,7 @@ read_n3_statement(SerdReader* const reader)
} else if (!tokcmp(reader, ctx.subject, "prefix", 6)) {
st = read_prefixID(reader, true, false);
} else if (!tokcmp(reader, ctx.subject, "graph", 5)) {
+ ctx.subject = pop_node(reader, ctx.subject);
read_ws_star(reader);
TRY(st, read_labelOrSubject(reader, &ctx.graph));
read_ws_star(reader);
@@ -1678,8 +1683,15 @@ read_n3_statement(SerdReader* const reader)
st = (eat_byte_check(reader, '.') == '.') ? SERD_SUCCESS
: SERD_ERR_BAD_SYNTAX;
}
+
+ ctx.subject = pop_node(reader, ctx.subject);
break;
}
+
+#ifndef NDEBUG
+ assert(reader->stack.size == orig_stack_size);
+#endif
+
return st;
}