On 10/11/2016 10:04 AM, Eric Blake wrote:
> On 10/11/2016 06:08 AM, Marc-André Lureau wrote:
>>> +++ b/block.c
>>> @@ -1640,7 +1640,8 @@ static BlockDriverState
>>> *bdrv_append_temp_snapshot(BlockDriverState *bs,
>>> qdict_put(snapshot_options, "file.driver",
>>> qdict_put(snapshot_options, "file.filename",
>>> - qstring_from_str(tmp_filename));
>>> + qstring_wrap_str(tmp_filename));
>>> + tmp_filename = NULL;
>>> qdict_put(snapshot_options, "driver",
>> You could also remove g_free(tmp_filename) from the normal return path
>> (this may please static analyzers).
> No. g_free(NULL) is safe, but we can also reach the 'out' label with
> tmp_filename still malloc'd prior to the place where we transfer it
> here, so the g_free() in the cleanup label is still required. The
> assignment to NULL here prevents a double free. The patch is correct as-is.
Spoke too soon. I see what you're saying - the normal return path now
has a dead g_free(NULL). It won't cause any grief to the static
analyzers, but it is a useless no-op function call, so I can indeed trim
it (the one before the label, not the one after).
static analyzers could catch the fact that you always call g_free(NULL) in this code path, please remove it.
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org