Hi Giacinto,

On 10/12/2018 11:54 AM, Giacinto Cifelli wrote:
Hi,

I trust you, but I have checked the code :)

you are right, the at_command_create may fail (on allocation error
from g_try_new0) and in this case it doesn't call the g_free.

However I have to say that the code leaks alot: overall the construct
is used 237 times, and only 98 times the g_free is called.

Umm, can you give me some examples? Do note that we have 2 patterns that we use:

Pattern 1 is the most common:

if (g_at_chat_send(...) > 0)
        return;

g_free/destroy(...);
CALLBACK_WITH_FAILURE();

Pattern 2 is what you want:

if (g_at_chat_send(...) == 0) {
        g_free/destroy(...);
        CALLBACK_WITH_FAILURE();
        return;
}

That said, according to Denis nowadays we don't use g_try_new0 because
the allocation won't fail, so we are unlikely to see it in action.
That is not really an excuse, and we can change the implementation of send() at any time. So you still need to be paranoid.

Regards,
-Denis
_______________________________________________
ofono mailing list
[email protected]
https://lists.ofono.org/mailman/listinfo/ofono

Reply via email to