[Ltrace-devel] [PATCH 1/6] Fix a memory leak in protolib_cache_maybe_load
Petr Machata
pmachata at redhat.com
Tue Apr 21 10:10:00 UTC 2015
Роман Донченко <dpb at corrigendum.ru> writes:
>>> - if (DICT_FIND_VAL(&cache->protolibs, &key, retp) == 0)
>>> + if (DICT_FIND_VAL(&cache->protolibs, &key, retp) == 0) {
>>> + if (*retp != NULL && own_key)
>>> + free((void *) key);
>>> return 0;
>>> + }
>>>
>>> if (strdup_if(&key, key, !own_key) < 0) {
>>> fprintf(stderr, "Couldn't cache %s: %s\n",
>>
>> This looks like the wrong fix. The one who allocated the key should
>> free it if protolib_cache_maybe_load returns a failure.
>
> But it returns a success here.
You are right, I didn't notice. Then it's fine. I'll push later today
together with the other fixes.
> In fact, I think we should take ownership of the key whenever the
> function returns zero, no matter what's in *retp. What do you think?
Yeah, if a key is passed in with own_key != 0, and the function returns
zero (i.e. a success), the caller should assume the key has been
consumed.
Thanks,
Petr
More information about the Ltrace-devel
mailing list