[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [libvirt-glib 1/6] Getters for GVirConfigDomainInterface attributes



On Wed, Feb 29, 2012 at 4:22 PM, Christophe Fergeau <cfergeau redhat com> wrote:
> On Wed, Feb 29, 2012 at 04:10:29PM +0200, Zeeshan Ali (Khattak) wrote:
>> Ah, I just realized why that is so:
>>
>> static char *libxml_str_to_glib(xmlChar *str)
>> {
>>     char *g_str;
>>
>>     if (str == NULL)
>>         return NULL;
>>     g_str = g_strdup((char *)str);
>>     xmlFree(str);
>>
>>     return g_str;
>> }
>>
>> This function is not needed as all you needed was to cast the 'xmlChar
>> *' to 'const gchar *' and return const from all users of this
>> function. Since we still are not API/ABI stable, I propose we change
>> this all over as there is no need to force apps to free strings all
>> the time and waste processor/memory on all these string
>> allocation/de-allocation.
>
> You'll still need to free the input "str", and you have no guarantee that
> xmlFree and g_free will call the same function to free memory in the end,

There wont' be any need for freeing if
gvir_config_xml_get_child_element_content() and similar functions
returned chid_node->content rather than  xmlNodeGetContent
(child_node). That way you never need to free any string. The original
gupnp-av code that you based this xml utils code on, does exactly
that. I wonder why you changed it?

> If you really insist on returning const from your getters, you'll need to
> cache their value in GVirDomainDevicePrivate

Not if its const returned from all functions.

-- 
Regards,

Zeeshan Ali (Khattak)
FSF member#5124


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]