From af79bfb919694a58852685f36a46ff32e401b58c Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Fri, 9 Sep 2016 18:54:34 -0700 Subject: Some refcounting fixes. Clearly this stuff is too complex overall. The plan is to move away from this and more towards pools, like proto2 uses. --- upb/descriptor/reader.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'upb/descriptor') diff --git a/upb/descriptor/reader.c b/upb/descriptor/reader.c index b515840..2b9e0e9 100644 --- a/upb/descriptor/reader.c +++ b/upb/descriptor/reader.c @@ -573,7 +573,7 @@ static size_t field_ondefaultval(void *closure, const void *hd, const char *buf, static bool field_ononeofindex(void *closure, const void *hd, int32_t index) { upb_descreader *r = closure; upb_oneofdef *o = upb_descreader_getoneof(r, index); - bool ok = upb_oneofdef_addfield(o, r->f, NULL, NULL); + bool ok = upb_oneofdef_addfield(o, r->f, &r->f, NULL); UPB_UNUSED(hd); UPB_ASSERT(ok); @@ -651,6 +651,7 @@ static void *msg_startext(void *closure, const void *hd) { return r; } +#include static void *msg_startfield(void *closure, const void *hd) { upb_descreader *r = closure; r->f = upb_fielddef_new(&r->f); @@ -663,9 +664,13 @@ static void *msg_startfield(void *closure, const void *hd) { static bool msg_endfield(void *closure, const void *hd) { upb_descreader *r = closure; upb_msgdef *m = upb_descreader_top(r); + bool ok; UPB_UNUSED(hd); - upb_msgdef_addfield(m, r->f, &r->f, NULL); + if (upb_fielddef_containingoneof(r->f) == NULL) { + ok = upb_msgdef_addfield(m, r->f, &r->f, NULL); + UPB_ASSERT(ok); + } r->f = NULL; return true; } -- cgit v1.2.3