From 2824ef300111f198132de215b57376587851cbd7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 23 Apr 2011 22:39:52 +0000 Subject: Fix stack memory leak (unbounded memory increasing per read triple, oops). Parsing of arbitrarily large ntriples files now takes place in a single page of memory, provided the data for a single triple fits in a single page (e.g. any case but very large literal objects). git-svn-id: http://svn.drobilla.net/serd/trunk@148 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/reader.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/reader.c b/src/reader.c index 10b812e9..a237bbf2 100644 --- a/src/reader.c +++ b/src/reader.c @@ -104,7 +104,7 @@ typedef enum { SERD_ERROR = 2, ///< Fatal error } SerdStatus; -static inline int +static int error(SerdReader reader, const char* fmt, ...) { va_list args; @@ -277,7 +277,8 @@ pop_string(SerdReader reader, Ref ref) assert(stack_is_top_string(reader, ref)); --reader->n_allocs; #endif - serd_stack_pop(&reader->stack, deref(reader, ref)->n_bytes); + SerdString* str = deref(reader, ref); + serd_stack_pop(&reader->stack, pad_size(sizeof(SerdString) + str->n_bytes)); } } @@ -1170,6 +1171,7 @@ read_predicateObjectList(SerdReader reader, ReadContext ctx) read_ws_star(reader); } } + pop_string(reader, predicate.value); return true; except: pop_string(reader, predicate.value); @@ -1230,7 +1232,7 @@ read_collection(SerdReader reader, ReadContext ctx, Node* dest) static Node read_subject(SerdReader reader, ReadContext ctx) { - Node subject = INTERNAL_NODE_NULL; + Node subject = INTERNAL_NODE_NULL; switch (peek_byte(reader)) { case '[': case '(': case '_': read_blank(reader, ctx, &subject); -- cgit v1.2.1