[libvirt] [PATCH] Allow relative path for qemu backing file
Jesse J Cook
jesse.cook at eads-na-security.com
Tue Apr 5 17:34:54 UTC 2011
On Tue, 2011-04-05 at 11:00 -0600, Eric Blake wrote:
> On 04/05/2011 10:55 AM, Jesse J Cook wrote:
> >>> + if ('/' != *(vol->backingStore.path)) {
> >>> + virAsprintf(&absolutePath, "%s/%s", pool->def->target.path,
> >>> + vol->backingStore.path);
> >>> +
> >>> + } else {
> >>> + virAsprintf(&absolutePath, "%s", vol->backingStore.path);
> >>
> >> strdup is more efficient here, and avoiding malloc in the first place
> >> even more so.
> >>
> >>> + }
> >>> + accessRetCode = access(absolutePath, R_OK);
> >>
> >> This could segfault on OOM.
> >>
> >>> + VIR_FREE(absolutePath);
> >
> > I believe there needs to be a NULL check here or absolute paths and
> > virAsprintf errors will segfault. I can patch if you don't beat me to
> > it.
Disregard. The code is correct.
> How so? absolutePath was initialized as NULL; is only ever set to
> non-null by a successful virAsprintf, and VIR_FREE works correctly
> (no-op) on a NULL argument. Put another way, are you missing that
> VIR_FREE already has an embedded NULL check?
>
Thank you for resolving my fundamental misunderstanding regarding the
behaviour of free(3). I did not realize free((void*)0) is safe.
--
Jesse Cook
Research Scientist
EADS NA Defense Security & Systems Solutions, Inc. (DS3)
1476 N. Green Mount Rd
O'Fallon, Illinois 62269
Office: 618.206.4032 x436
Email: jesse.cook at eads-na-security.com
http://www.eads-na-security.com
More information about the libvir-list
mailing list