mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
qemuDomainSaveImageOpen: Automatically close 'fd' if unneeded
Use VIR_AUTOCLOSE to declare it and remove all internal closing of the filedescriptor. This will allow getting rid of 'error' completely. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
3850add603
commit
db907a4d9c
@ -6691,7 +6691,7 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver,
|
||||
bool open_write,
|
||||
bool unlink_corrupt)
|
||||
{
|
||||
int fd = -1;
|
||||
VIR_AUTOCLOSE fd = -1;
|
||||
int ret = -1;
|
||||
g_autoptr(virQEMUSaveData) data = NULL;
|
||||
virQEMUSaveHeaderPtr header;
|
||||
@ -6723,7 +6723,7 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver,
|
||||
header = &data->header;
|
||||
if (saferead(fd, header, sizeof(*header)) != sizeof(*header)) {
|
||||
if (unlink_corrupt) {
|
||||
if (VIR_CLOSE(fd) < 0 || unlink(path) < 0) {
|
||||
if (unlink(path) < 0) {
|
||||
virReportSystemError(errno,
|
||||
_("cannot remove corrupt file: %s"),
|
||||
path);
|
||||
@ -6744,7 +6744,7 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver,
|
||||
sizeof(header->magic)) == 0) {
|
||||
msg = _("save image is incomplete");
|
||||
if (unlink_corrupt) {
|
||||
if (VIR_CLOSE(fd) < 0 || unlink(path) < 0) {
|
||||
if (unlink(path) < 0) {
|
||||
virReportSystemError(errno,
|
||||
_("cannot remove corrupt file: %s"),
|
||||
path);
|
||||
@ -6812,10 +6812,12 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver,
|
||||
*ret_def = g_steal_pointer(&def);
|
||||
*ret_data = g_steal_pointer(&data);
|
||||
|
||||
return fd;
|
||||
ret = fd;
|
||||
fd = -1;
|
||||
|
||||
return ret;
|
||||
|
||||
error:
|
||||
VIR_FORCE_CLOSE(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user