From bcbcdadbd2821742353b483f261695cbb941188c Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 11 Oct 2020 15:44:38 -0700 Subject: [PATCH] Fixed memory leak. --- upb/decode.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/upb/decode.c b/upb/decode.c index 59cb3f6ff9..b0b6105d3d 100644 --- a/upb/decode.c +++ b/upb/decode.c @@ -141,6 +141,7 @@ static const int8_t delim_ops[37] = { typedef struct { const char *limit; /* End of delimited region or end of buffer. */ upb_arena arena; + upb_arena *orig_parent; int depth; uint32_t end_group; /* Set to field number of END_GROUP tag, if any. */ jmp_buf err; @@ -610,9 +611,13 @@ bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l, if (size == 0) return true; state.limit = buf + size; - state.arena = *arena; state.depth = 64; state.end_group = 0; + state.orig_parent = arena->parent; + state.arena = *arena; + if (arena->parent == arena) { + state.arena.parent = &state.arena; + } if (setjmp(state.err)) { ok = false; @@ -622,6 +627,7 @@ bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l, } *arena = state.arena; + arena->parent = state.orig_parent; return ok; }