properly handle return codes
[project/rpcd.git] / file.c
diff --git a/file.c b/file.c
index fdc63966d8b28aeb4cbaaca28234f03c31afd612..3831c547db8dced04c6f6e623c9c47ea060729dd 100644 (file)
--- a/file.c
+++ b/file.c
@@ -199,6 +199,7 @@ rpc_file_read(struct ubus_context *ctx, struct ubus_object *obj,
        blobmsg_add_string_buffer(&buf);
 
        ubus_send_reply(ctx, req, buf.head);
+       blob_buf_free(&buf);
        rv = UBUS_STATUS_OK;
 
 out:
@@ -220,7 +221,7 @@ rpc_file_write(struct ubus_context *ctx, struct ubus_object *obj,
        if (!tb[RPC_F_RW_PATH] || !tb[RPC_F_RW_DATA])
                return UBUS_STATUS_INVALID_ARGUMENT;
 
-       if ((fd = open(blobmsg_data(tb[RPC_F_RW_PATH]), O_CREAT | O_TRUNC | O_WRONLY)) < 0)
+       if ((fd = open(blobmsg_data(tb[RPC_F_RW_PATH]), O_CREAT | O_TRUNC | O_WRONLY, 0666)) < 0)
                return rpc_errno_status();
 
        if (write(fd, blobmsg_data(tb[RPC_F_RW_DATA]), blobmsg_data_len(tb[RPC_F_RW_DATA])) < 0)
@@ -266,8 +267,11 @@ rpc_file_list(struct ubus_context *ctx, struct ubus_object *obj,
                blobmsg_close_table(&buf, d);
        }
 
+       closedir(fd);
+
        blobmsg_close_array(&buf, c);
        ubus_send_reply(ctx, req, buf.head);
+       blob_buf_free(&buf);
 
        return 0;
 }
@@ -307,6 +311,7 @@ rpc_file_stat(struct ubus_context *ctx, struct ubus_object *obj,
        blobmsg_add_u32(&buf, "gid",   s.st_gid);
 
        ubus_send_reply(ctx, req, buf.head);
+       blob_buf_free(&buf);
 
        return 0;
 }
@@ -393,6 +398,7 @@ rpc_file_exec_reply(struct rpc_file_exec_context *c, int rv)
                rpc_ustream_to_blobmsg(&c->epipe.stream, "stderr");
 
                ubus_send_reply(c->context, &c->request, buf.head);
+               blob_buf_free(&buf);
        }
 
        ubus_complete_deferred_request(c->context, &c->request, rv);