mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
openvzGetVEID: don't leak (memory + file descriptor)
* src/openvz/openvz_conf.c (openvzGetVEID): Always call fclose. Diagnose parse failure also when vzlist output is empty. If somehow we read a -1, diagnose that (albeit as a parse failure).
This commit is contained in:
parent
8ac0334ebd
commit
f3439c7eae
@ -964,6 +964,7 @@ int openvzGetVEID(const char *name) {
|
|||||||
char *cmd;
|
char *cmd;
|
||||||
int veid;
|
int veid;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
bool ok;
|
||||||
|
|
||||||
if (virAsprintf(&cmd, "%s %s -ovpsid -H", VZLIST, name) < 0) {
|
if (virAsprintf(&cmd, "%s %s -ovpsid -H", VZLIST, name) < 0) {
|
||||||
openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s",
|
openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -979,18 +980,12 @@ int openvzGetVEID(const char *name) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fscanf(fp, "%d\n", &veid ) != 1) {
|
ok = fscanf(fp, "%d\n", &veid ) == 1;
|
||||||
if (feof(fp))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
openvzError(NULL, VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"%s", _("Failed to parse vzlist output"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
return veid;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
if (ok && veid >= 0)
|
||||||
|
return veid;
|
||||||
|
|
||||||
|
openvzError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("Failed to parse vzlist output"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user