From d05eac2890195e0d929263b4a1b28b813bd09e85 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 30 Aug 2009 21:11:03 -0700 Subject: Properly free dynamic memory that has not been reused during parsing. --- src/upb_msg.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/upb_msg.c b/src/upb_msg.c index ce443e1..d9a600f 100644 --- a/src/upb_msg.c +++ b/src/upb_msg.c @@ -245,8 +245,17 @@ static void end_cb(void *udata) { struct upb_msg_parser *mp = udata; struct upb_msg *msg = mp->top->msg; - /* TODO: free any remaining dynamic storage that was not reused. */ - (void)msg; + struct upb_msgdef *def = msg->def; + + // Free any remaining dynamic storage we did not reuse. + for(uint32_t i = 0; i < def->num_fields; i++) { + struct upb_msg_fielddef *f = &def->fields[i]; + union upb_value_ptr p = upb_msg_getptr(msg, f); + if(upb_msg_isset(msg, f) || !upb_field_ismm(f) || !*p.msg) continue; + union upb_mmptr mmptr = upb_mmptr_read(p, f->type); + upb_mm_unref(mmptr, f->type); + } + mp->top--; } -- cgit v1.2.3