diff options
author | Nicolas CARRIER <nicolas.carrier.ext@parrot.com> | 2012-04-13 13:51:44 +0200 |
---|---|---|
committer | Thomas Graf <tgraf@redhat.com> | 2012-04-19 18:51:17 +0200 |
commit | f54ac3d55f9acc3786369509df1bdff737e6d444 (patch) | |
tree | 4a619e37547e0fb7a0e6c54b521e51b39c5fa6bf /lib/route | |
parent | 7d47666eb3c414feb8901970d35b96461214c2bf (diff) | |
download | libnl-f54ac3d55f9acc3786369509df1bdff737e6d444.tar.gz |
Memory leak in classid.c
I'm using libnl in a program which I give to valgrind
in order to track memory errors / leaks. When my program
exits, it complains about non-freed memory, allocated in
3 places in classid.c, at lines 280, 284 and 289.
It seems related to the module's constructor classid_init
which allocates resources, with no destructor to free it.
The attached patch tries to fix this issue by registering
a destructor which performs the tree liberation at exit.
Diffstat (limited to 'lib/route')
-rw-r--r-- | lib/route/classid.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/route/classid.c b/lib/route/classid.c index abed244..da531bd 100644 --- a/lib/route/classid.c +++ b/lib/route/classid.c @@ -41,7 +41,7 @@ static int compare_id(const void *pa, const void *pb) if (ma->classid < mb->classid) return -1; - + if (ma->classid > mb->classid) return 1; @@ -217,7 +217,7 @@ not_a_number: } else { /* XXXX:YYYY */ uint32_t l; - + update: l = strtoul(colon+1, &end, 16); @@ -296,7 +296,7 @@ static int classid_map_add(uint32_t classid, const char *name) /** * (Re-)read classid file - * + * * Rereads the contents of the classid file (typically found at the location * /etc/libnl/classid) and refreshes the classid maps. * @@ -409,7 +409,7 @@ int rtnl_classid_generate(const char *name, uint32_t *result, uint32_t parent) fclose(fd); if ((err = classid_map_add(classid, name)) < 0) { - /* + /* * Error adding classid map, re-read classid file is best * option here. It is likely to fail as well but better * than nothing, entry was added to the file already anyway. @@ -438,4 +438,12 @@ static void __init classid_init(void) fprintf(stderr, "Failed to read classid file: %s\n", nl_geterror(err)); } +static void __exit classid_exit(void) +{ + void free_map(void *map) { + free(((struct classid_map *)map)->name); + free(map); + }; + tdestroy(id_root, free_map); +} /** @} */ |