diff options
author | Joshua Haberman <joshua@reverberate.org> | 2009-08-30 21:11:03 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2009-08-30 21:11:03 -0700 |
commit | d05eac2890195e0d929263b4a1b28b813bd09e85 (patch) | |
tree | 2a2fe5cface4a97d48e3bed614d8f1674803aaaa /src/upb_msg.c | |
parent | a022e6ebdba0cf5e08d101af235b7e6eaebee34e (diff) |
Properly free dynamic memory that has not been reused during parsing.
Diffstat (limited to 'src/upb_msg.c')
-rw-r--r-- | src/upb_msg.c | 13 |
1 files changed, 11 insertions, 2 deletions
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--; } |