diff options
author | David Robillard <d@drobilla.net> | 2011-04-23 22:39:52 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-04-23 22:39:52 +0000 |
commit | 2824ef300111f198132de215b57376587851cbd7 (patch) | |
tree | 0cbf55fcdddce6f1d2fdced395bd5bdaaf2603e5 | |
parent | c8bca421254840c7eb249e138d06f6ae0b008290 (diff) | |
download | serd-2824ef300111f198132de215b57376587851cbd7.tar.gz serd-2824ef300111f198132de215b57376587851cbd7.tar.bz2 serd-2824ef300111f198132de215b57376587851cbd7.zip |
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
-rw-r--r-- | src/reader.c | 8 |
1 files changed, 5 insertions, 3 deletions
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); |