Mem-leaks in 'test-as.c'

Message ID
State Dropped
Series Mem-leaks in 'test-as.c' |

Commit Message

Gisle Vanem Oct. 24, 2020, 8:12 a.m. UTC
  Michael Tremer wrote:

> First thing to know is that we use reference counting for all objects.
> So every pointer that refers to an object has to decrement
> the counter when it no longer needs it. The object will be automatically
> cleaned up after nothing needs it any more.

In 'test-as.c', I get a huge amount of leaks in MSVC
debug-mode. Since 'loc_database_enumerator_unref()' just
unreferences itself and not the 'as' (working as designed?)
IMHO it should be:

With that patch, no reported leaks.

Could be leaks in 'libloc' itself too; haven't checked yet.


--- a/test-as.c 2020-10-19 17:35:01
+++ b/test-as.c 2020-10-24 10:01:57
@@ -111,12 +111,17 @@ 

         while (as) {
                 printf("Found AS%d: %s\n", loc_as_get_number(as), loc_as_get_name(as));

-               err = loc_database_enumerator_next_as(enumerator, &as);
+               struct loc_as* as_next;
+               err = loc_database_enumerator_next_as(enumerator, &as_next);
                 if (err) {
                         fprintf(stderr, "Could not enumerate next AS\n");
+               loc_as_unref(as);
+               as = as_next;