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:
Jim Meyering 2010-02-25 19:24:50 +01:00
parent 8ac0334ebd
commit f3439c7eae
1 changed files with 7 additions and 12 deletions

View File

@ -964,6 +964,7 @@ int openvzGetVEID(const char *name) {
char *cmd;
int veid;
FILE *fp;
bool ok;
if (virAsprintf(&cmd, "%s %s -ovpsid -H", VZLIST, name) < 0) {
openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s",
@ -979,18 +980,12 @@ int openvzGetVEID(const char *name) {
return -1;
}
if (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:
ok = fscanf(fp, "%d\n", &veid ) == 1;
fclose(fp);
if (ok && veid >= 0)
return veid;
openvzError(NULL, VIR_ERR_INTERNAL_ERROR,
"%s", _("Failed to parse vzlist output"));
return -1;
}