summaryrefslogtreecommitdiffstats
path: root/src/power/power.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/power/power.c')
-rw-r--r--src/power/power.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/power/power.c b/src/power/power.c
index 646aa45..96960be 100644
--- a/src/power/power.c
+++ b/src/power/power.c
@@ -78,6 +78,9 @@ Power *power_new(const CMPIBroker *_cb, const CMPIContext *ctx)
{
lmi_init(provider_name, _cb, ctx, provider_config_defaults);
Power *power = malloc(sizeof(Power));
+ if (power == NULL) {
+ return NULL;
+ }
power->broker = _cb;
power->instances = 0;
power->requestedPowerState = LMI_AssociatedPowerManagementService_RequestedPowerState_Unknown;
@@ -104,7 +107,9 @@ void power_destroy(Power *power)
Power *power_ref(const CMPIBroker *_cb, const CMPIContext *ctx)
{
if (_power == NULL) {
- _power = power_new(_cb, ctx);
+ if ((_power = power_new(_cb, ctx)) == NULL) {
+ return NULL;
+ }
}
MUTEX_LOCK(_power);
_power->instances++;
@@ -114,6 +119,9 @@ Power *power_ref(const CMPIBroker *_cb, const CMPIContext *ctx)
void power_unref(Power *power)
{
+ if (power == NULL) {
+ return;
+ }
MUTEX_LOCK(power);
power->instances--;
MUTEX_UNLOCK(power);
@@ -246,6 +254,9 @@ int power_request_power_state(Power *power, unsigned short state)
int count, found = 0;
unsigned short *states = power_available_requested_power_states(power, &count);
+ if (states == NULL) {
+ return CMPI_RC_ERR_FAILED;
+ }
for (int i = 0; i < count; ++i) {
if (states[i] == state) {
found = 1;
@@ -259,6 +270,10 @@ int power_request_power_state(Power *power, unsigned short state)
}
PowerStateChangeJob *powerStateChangeJob = malloc(sizeof(PowerStateChangeJob));
+ if (powerStateChangeJob == NULL) {
+ error("Memory allocation failed");
+ return CMPI_RC_ERR_FAILED;
+ }
powerStateChangeJob->id = job_max_id++;
powerStateChangeJob->broker = power->broker;
powerStateChangeJob->power = power;
@@ -303,6 +318,10 @@ int power_request_power_state(Power *power, unsigned short state)
unsigned short *power_available_requested_power_states(Power *power, int *count)
{
unsigned short *list = malloc(17 * sizeof(unsigned short));
+ if (list == NULL) {
+ error("Memory allocation failed");
+ return NULL;
+ }
int i = 0;
/* 1 Other