Adapt to VIR_ALLOC and virAsprintf in src/secret/*

This commit is contained in:
Michal Privoznik 2013-07-04 12:15:29 +02:00
parent ff50bdfda3
commit 92a33a12a1

View File

@ -173,10 +173,8 @@ replaceFile(const char *filename, void *data, size_t size)
char *tmp_path = NULL; char *tmp_path = NULL;
int fd = -1, ret = -1; int fd = -1, ret = -1;
if (virAsprintf(&tmp_path, "%sXXXXXX", filename) < 0) { if (virAsprintf(&tmp_path, "%sXXXXXX", filename) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
fd = mkostemp(tmp_path, O_CLOEXEC); fd = mkostemp(tmp_path, O_CLOEXEC);
if (fd == -1) { if (fd == -1) {
virReportSystemError(errno, _("mkostemp('%s') failed"), tmp_path); virReportSystemError(errno, _("mkostemp('%s') failed"), tmp_path);
@ -225,10 +223,7 @@ secretComputePath(virSecretDriverStatePtr driver,
virUUIDFormat(secret->def->uuid, uuidstr); virUUIDFormat(secret->def->uuid, uuidstr);
if (virAsprintf(&ret, "%s/%s%s", driver->directory, uuidstr, suffix) < 0) ignore_value(virAsprintf(&ret, "%s/%s%s", driver->directory, uuidstr, suffix));
/* ret is NULL */
virReportOOMError();
return ret; return ret;
} }
@ -397,10 +392,8 @@ secretLoadValue(virSecretDriverStatePtr driver,
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC_N(contents, st.st_size) < 0) { if (VIR_ALLOC_N(contents, st.st_size) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (saferead(fd, contents, st.st_size) != st.st_size) { if (saferead(fd, contents, st.st_size) != st.st_size) {
virReportSystemError(errno, _("cannot read '%s'"), filename); virReportSystemError(errno, _("cannot read '%s'"), filename);
goto cleanup; goto cleanup;
@ -412,10 +405,8 @@ secretLoadValue(virSecretDriverStatePtr driver,
_("invalid base64 in '%s'"), filename); _("invalid base64 in '%s'"), filename);
goto cleanup; goto cleanup;
} }
if (value == NULL) { if (value == NULL)
virReportOOMError();
goto cleanup; goto cleanup;
}
secret->value = (unsigned char *)value; secret->value = (unsigned char *)value;
value = NULL; value = NULL;
@ -446,10 +437,8 @@ secretLoad(virSecretDriverStatePtr driver,
char *xml_filename; char *xml_filename;
if (virAsprintf(&xml_filename, "%s/%s", driver->directory, if (virAsprintf(&xml_filename, "%s/%s", driver->directory,
xml_basename) < 0) { xml_basename) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
def = virSecretDefParseFile(xml_filename); def = virSecretDefParseFile(xml_filename);
if (def == NULL) if (def == NULL)
goto cleanup; goto cleanup;
@ -458,10 +447,8 @@ secretLoad(virSecretDriverStatePtr driver,
if (secretLoadValidateUUID(def, xml_basename) < 0) if (secretLoadValidateUUID(def, xml_basename) < 0)
goto cleanup; goto cleanup;
if (VIR_ALLOC(secret) < 0) { if (VIR_ALLOC(secret) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
secret->def = def; secret->def = def;
def = NULL; def = NULL;
@ -598,10 +585,8 @@ secretConnectListSecrets(virConnectPtr conn, char **uuids, int maxuuids)
continue; continue;
if (i == maxuuids) if (i == maxuuids)
break; break;
if (VIR_ALLOC_N(uuidstr, VIR_UUID_STRING_BUFLEN) < 0) { if (VIR_ALLOC_N(uuidstr, VIR_UUID_STRING_BUFLEN) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
virUUIDFormat(secret->def->uuid, uuidstr); virUUIDFormat(secret->def->uuid, uuidstr);
uuids[i] = uuidstr; uuids[i] = uuidstr;
i++; i++;
@ -664,12 +649,8 @@ secretConnectListAllSecrets(virConnectPtr conn,
for (entry = driver->secrets; entry != NULL; entry = entry->next) for (entry = driver->secrets; entry != NULL; entry = entry->next)
nsecrets++; nsecrets++;
if (secrets) { if (secrets && VIR_ALLOC_N(tmp_secrets, nsecrets + 1) < 0)
if (VIR_ALLOC_N(tmp_secrets, nsecrets + 1) < 0) { goto cleanup;
virReportOOMError();
goto cleanup;
}
}
for (entry = driver->secrets; entry != NULL; entry = entry->next) { for (entry = driver->secrets; entry != NULL; entry = entry->next) {
if (!virConnectListAllSecretsCheckACL(conn, if (!virConnectListAllSecretsCheckACL(conn,
@ -825,10 +806,8 @@ secretDefineXML(virConnectPtr conn, const char *xml,
} }
/* No existing secret at all, create one */ /* No existing secret at all, create one */
if (VIR_ALLOC(secret) < 0) { if (VIR_ALLOC(secret) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
listInsert(&driver->secrets, secret); listInsert(&driver->secrets, secret);
secret->def = new_attrs; secret->def = new_attrs;
@ -949,10 +928,8 @@ secretSetValue(virSecretPtr obj, const unsigned char *value,
virCheckFlags(0, -1); virCheckFlags(0, -1);
if (VIR_ALLOC_N(new_value, value_size) < 0) { if (VIR_ALLOC_N(new_value, value_size) < 0)
virReportOOMError();
return -1; return -1;
}
secretDriverLock(driver); secretDriverLock(driver);
@ -1041,10 +1018,8 @@ secretGetValue(virSecretPtr obj, size_t *value_size, unsigned int flags,
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC_N(ret, secret->value_size) < 0) { if (VIR_ALLOC_N(ret, secret->value_size) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
memcpy(ret, secret->value, secret->value_size); memcpy(ret, secret->value, secret->value_size);
*value_size = secret->value_size; *value_size = secret->value_size;
@ -1145,8 +1120,8 @@ secretStateInitialize(bool privileged,
if (!base) if (!base)
goto error; goto error;
} }
if (virAsprintf(&driverState->directory, "%s/secrets", base) == -1) if (virAsprintf(&driverState->directory, "%s/secrets", base) < 0)
goto out_of_memory; goto error;
VIR_FREE(base); VIR_FREE(base);
if (loadSecrets(driverState, &driverState->secrets) < 0) if (loadSecrets(driverState, &driverState->secrets) < 0)
@ -1155,8 +1130,6 @@ secretStateInitialize(bool privileged,
secretDriverUnlock(driverState); secretDriverUnlock(driverState);
return 0; return 0;
out_of_memory:
VIR_ERROR(_("Out of memory initializing secrets"));
error: error:
VIR_FREE(base); VIR_FREE(base);
secretDriverUnlock(driverState); secretDriverUnlock(driverState);