diff options
author | Petr Machata <pmachata@redhat.com> | 2012-12-13 18:22:32 +0100 |
---|---|---|
committer | Petr Machata <pmachata@redhat.com> | 2013-03-08 22:55:30 +0100 |
commit | 7f1d856ea4882a23461886d0f589244cc11f0b2f (patch) | |
tree | 0794a3791a7dc7460e6f8cf122c26aae19dbcac4 /prototype.c | |
parent | 93eb0ee606dc4425cc2f1019f5e549acf77f40b0 (diff) | |
download | ltrace-7f1d856ea4882a23461886d0f589244cc11f0b2f.tar.gz |
Fix memory errors
With this, valgrind run of ltrace on x86_64 is clean.
Diffstat (limited to 'prototype.c')
-rw-r--r-- | prototype.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/prototype.c b/prototype.c index bb13525..1ce6ae7 100644 --- a/prototype.c +++ b/prototype.c @@ -142,6 +142,8 @@ protolib_init(struct protolib *plib) dict_hash_string, dict_eq_string, NULL); VECT_INIT(&plib->imports, struct protolib *); + + plib->refs = 0; } static void @@ -159,6 +161,8 @@ destroy_named_type_cb(struct named_type *named, void *data) void protolib_destroy(struct protolib *plib) { + assert(plib->refs == 0); + VECT_DESTROY(&plib->imports, struct prototype *, NULL, NULL); DICT_DESTROY(&plib->prototypes, const char *, struct prototype, @@ -323,7 +327,11 @@ destroy_protolib_cb(struct protolib **plibp, void *data) { assert(plibp != NULL); assert(*plibp != NULL); - protolib_destroy(*plibp); + + if (--(*plibp)->refs == 0) { + protolib_destroy(*plibp); + free(*plibp); + } } void @@ -621,6 +629,8 @@ protolib_cache_protolib(struct protolib_cache *cache, int rc = DICT_INSERT(&cache->protolibs, &filename, &plib); if (rc < 0 && own_filename) free((char *)filename); + if (rc == 0) + plib->refs++; return rc; } |