Re: [PATCH 03/15] service: Leverage 'service_set_pac' function.
Denis Kenzior <[email protected]> Tue, 4 Mar 2025 13:51:55 -0600
| Newsgroups | dev.linux.lists.connman |
|---|---|
| Message-ID | <[email protected]> |
Hi Grant,
<snip>
>>> @@ -770,8 +770,7 @@ static int service_load(struct connman_service *service)
>>> str = g_key_file_get_string(keyfile,
>>> service->identifier, "Proxy.URL", NULL);
>>> if (str) {
>>> - g_free(service->pac);
>>> - service->pac = str;
>>> + service_set_pac(service, str, false);
>>
>> Does this leak str?
>
> I do not believe so, no. service_set_pac now handles the same:
>
> g_free(service->pac);
>
> if (pac && strlen(pac) > 0)
> service->pac = g_strstrip(g_strdup(pac));
> else
> service->pac = NULL;
>
> except now instead of being individually duplicated and scattered around to several call sites, it is all handled in one with service_set_pac.
service_set_pac receives a const char *. But g_key_file_get_string() returns a
newly allocated char *, which is assigned to 'str'. What frees it?
[1]
https://www.manpagez.com/html/glib/glib-2.42.0/glib-Key-value-file-parser.php#g-key-file-get-string
Regards,
-Denis