This function has the warn_unused_result attribute set, so go through
and check the result everywhere it is used.
Signed-off-by: Russell Bryant <rbryant(a)redhat.com>
---
src/lib/services.c | 19 +++++++++++++++----
src/lib/services_linux.c | 4 +++-
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/lib/services.c b/src/lib/services.c
index 3241002..ebb0e4f 100644
--- a/src/lib/services.c
+++ b/src/lib/services.c
@@ -94,14 +94,18 @@ svc_action_t *resources_action_create(
op->standard = strdup(standard);
op->agent = strdup(agent);
op->sequence = ++operations;
- asprintf(&op->id, "%s_%s_%d", name, action, interval);
+ if (asprintf(&op->id, "%s_%s_%d", name, action, interval) == -1) {
+ goto return_error;
+ }
if(strcasecmp(standard, "ocf") == 0) {
op->provider = strdup(provider);
op->params = params;
- asprintf(&op->opaque->exec, "%s/resource.d/%s/%s",
- OCF_ROOT, provider, agent);
+ if (asprintf(&op->opaque->exec, "%s/resource.d/%s/%s",
+ OCF_ROOT, provider, agent) == -1) {
+ goto return_error;
+ }
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(action);
@@ -113,7 +117,9 @@ svc_action_t *resources_action_create(
op->opaque->exec = strdup(SYSTEMCTL);
op->opaque->args[0] = strdup(SYSTEMCTL);
op->opaque->args[1] = strdup(action);
- asprintf(&service, "%s.service", agent);
+ if (asprintf(&service, "%s.service", agent) == -1) {
+ goto return_error;
+ }
op->opaque->args[2] = service;
} else {
mh_err("Unknown resource standard: %s", standard);
@@ -122,6 +128,11 @@ svc_action_t *resources_action_create(
}
return op;
+
+return_error:
+ services_action_free(op);
+
+ return NULL;
}
svc_action_t *
diff --git a/src/lib/services_linux.c b/src/lib/services_linux.c
index 75d0df9..92e62f1 100644
--- a/src/lib/services_linux.c
+++ b/src/lib/services_linux.c
@@ -472,7 +472,9 @@ services_os_set_exec(svc_action_t *op)
op->opaque->args[3] = NULL;
} else {
- asprintf(&op->opaque->exec, "%s/%s", LSB_ROOT,
op->agent);
+ if (asprintf(&op->opaque->exec, "%s/%s", LSB_ROOT,
op->agent) == -1) {
+ return;
+ }
op->opaque->args[0] = strdup(op->opaque->exec);
op->opaque->args[1] = strdup(op->action);
op->opaque->args[2] = NULL;
--
1.7.6.4