From 336268b3d7e8860e86171650882d0a4f7d62ecfd Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 10 Aug 2011 19:46:08 -0700 Subject: Fixed a few memory leaks and Makefile tweaks. --- Makefile | 7 ++++--- upb/def.c | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6fb994a..314b69b 100644 --- a/Makefile +++ b/Makefile @@ -120,7 +120,7 @@ clean_leave_profile: rm -rf upb/descriptor.pb rm -rf tools/upbc deps rm -rf lang_ext/lua/upb.so - cd lang_ext/python && python setup.py clean --all + rm -rf lang_ext/python/build clean: clean_leave_profile rm -rf $(call rwildcard,,*.gcno) $(call rwildcard,,*.gcda) @@ -397,11 +397,12 @@ lang_ext/lua/upb.so: lang_ext/lua/upb.c $(LIBUPB_PIC) # Python extension ############################################################# +PYTHON=python2.6-dbg PYTHONEXT=lang_ext/python/build/install/lib/python/upb/__init__.so python: $(PYTHONEXT) $(PYTHONEXT): $(LIBUPB_PIC) lang_ext/python/upb.c $(E) PYTHON lang_ext/python/upb.c - $(Q) cd lang_ext/python && python setup.py build install --home=build/install + $(Q) cd lang_ext/python && $(PYTHON) setup.py build --debug install --home=build/install pythontest: $(PYTHONEXT) - cd lang_ext/python && cp test.py build/install/lib/python && python ./build/install/lib/python/test.py + cd lang_ext/python && cp test.py build/install/lib/python && valgrind $(PYTHON) ./build/install/lib/python/test.py diff --git a/upb/def.c b/upb/def.c index 7de247e..6d2930c 100644 --- a/upb/def.c +++ b/upb/def.c @@ -226,6 +226,11 @@ static void upb_fielddef_free(upb_fielddef *f) { if (upb_isstring(f)) { free(upb_value_getptr(f->defaultval)); } + if (f->def) { + // We own a ref on the subdef iff we are not part of a msgdef. + assert((f->msgdef == NULL) == (upb_dyncast_unresolveddef(f->def) != NULL)); + if (f->msgdef == NULL) upb_def_unref(f->def); + } free(f->name); free(f); } @@ -305,6 +310,7 @@ bool upb_fielddef_setnumber(upb_fielddef *f, int32_t number) { bool upb_fielddef_setname(upb_fielddef *f, const char *name) { assert(f->msgdef == NULL); + free(f->name); f->name = strdup(name); return true; } -- cgit v1.2.3