resource-asm: fix memory handling.
authorIsmo Puustinen <ismo.puustinen@intel.com>
Tue, 4 Dec 2012 13:22:03 +0000 (15:22 +0200)
committerKrisztian Litkey <krisztian.litkey@intel.com>
Thu, 8 Jan 2015 16:37:09 +0000 (18:37 +0200)
src/plugins/plugin-resource-asm.c
src/plugins/resource-asm/asm-bridge.c

index 1002c90..306a30a 100644 (file)
@@ -386,6 +386,9 @@ static asm_to_lib_t *process_msg(lib_to_asm_t *msg, asm_data_t *ctx)
 
     reply = mrp_allocz(sizeof(asm_to_lib_t));
 
+    if (!reply)
+        return NULL;
+
     reply->instance_id = pid;
     reply->check_privilege = TRUE;
 
@@ -505,6 +508,9 @@ static asm_to_lib_t *process_msg(lib_to_asm_t *msg, asm_data_t *ctx)
                 uint32_t handle = client->current_handle++;
                 resource_set_data_t *d = mrp_allocz(sizeof(resource_set_data_t));
 
+                if (!d)
+                    goto error;
+
                 d->handle = handle;
                 d->ctx = ctx;
                 d->pid = pid;
@@ -530,6 +536,7 @@ static asm_to_lib_t *process_msg(lib_to_asm_t *msg, asm_data_t *ctx)
 
                     if (!d->rset) {
                         mrp_log_error("Failed to create resource set!");
+                        mrp_free(d);
                         goto error;
                     }
 
@@ -1062,6 +1069,9 @@ static int asm_init(mrp_plugin_t *plugin)
 
 error:
 
+    if (!ctx)
+        return FALSE;
+
     if (ctx->pid) {
         kill(ctx->pid, SIGTERM);
         ctx->pid = 0;
index c0bb9f0..62d6983 100644 (file)
@@ -139,10 +139,8 @@ static int process_msg(ASM_msg_lib_to_asm_t *msg, ctx_t *ctx)
     res.sound_state = msg->data.sound_state;
     res.system_resource = msg->data.system_resource;
 #ifdef USE_SECURITY
-    {
-        cookie_len = COOKIE_SIZE;
-        cookie = msg->data.cookie;
-    }
+    cookie_len = COOKIE_SIZE;
+    cookie = msg->data.cookie;
 #endif
 
     res.n_cookie_bytes = cookie_len;
@@ -273,9 +271,11 @@ static int send_callback_to_client(asm_to_lib_cb_t *msg, ctx_t *ctx)
                     msg->instance_id, msg->handle);
         }
         else {
-
             wf = mrp_allocz(sizeof(struct watched_file));
 
+            if (!wf)
+                goto error;
+
             wf->watched_file = mrp_strdup(rd_filename);
             wf->ctx = ctx;
             wf->instance_id = msg->instance_id;
@@ -474,6 +474,7 @@ int main (int argc, char **argv)
     mrp_htbl_config_t watches_conf;
 
     ctx_t ctx;
+    ctx.watched_files = NULL;
 
     /* set up the signal handling */