[Libvirt-cim] [PATCH 1/6] VSMS: Coverity cleanups
John Ferlan
jferlan at redhat.com
Wed Feb 5 13:14:19 UTC 2014
On 02/04/2014 10:24 AM, Boris Fiuczynski wrote:
> On 01/22/2014 08:30 PM, John Ferlan wrote:
<...snip...>
>> @@ -2798,7 +2801,8 @@ static CMPIStatus update_system_settings(const CMPIContext *context,
>> }
>>
>> if ((dominfo->uuid == NULL) || (STREQ(dominfo->uuid, ""))) {
>> - dominfo->uuid = strdup(uuid);
>> + dominfo->uuid = uuid;
>> + uuid = NULL;
> I am getting a compile error here and below for the free of uuid.
> error: assignment discards 'const' qualifier from pointer target type
> [-Werror]
> error: passing argument 1 of 'free' discards 'const' qualifier from
> pointer target type [-Werror]
>
> Removing the const in the declaration works... for me.
>
Strange - mine didn't complain, but one would also think that the prior
code doing a uuid = strdup(dominfo->uuid); would elicit the same issue!
Anyway, adjusted the definition from "const char *uuid" to just "char
*uuid".
In actually reading and thinking about the code, do you think a
"free(dominfo->uuid);" prior to the setting should be added too? In the
event it was the empty string? Not sure how it gets set that way, but
since cleanup_dominfo() would free() it if it was "" or whatever real
value is, then I suppose better safe than sorry.
Tks,
John
>> } else if (!STREQ(uuid, dominfo->uuid)) {
>> cu_statusf(_BROKER, &s,
>> CMPI_RC_ERR_FAILED,
>> @@ -2829,6 +2833,7 @@ static CMPIStatus update_system_settings(const CMPIContext *context,
>> }
>>
>> out:
>> + free(uuid);
>> free(xml);
>> virDomainFree(dom);
>> virConnectClose(conn);
>>
>
>
More information about the Libvirt-cim
mailing list