libubus: close file descriptor after passing it in the status msg
authorFelix Fietkau <nbd@openwrt.org>
Thu, 27 Feb 2014 15:48:53 +0000 (16:48 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 27 Feb 2014 15:48:55 +0000 (16:48 +0100)
Simplifies handling of non-deferred requests

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
examples/server.c
libubus-io.c

index bfad363011161d2dccd062ac65de1bc164e95287..95eba5e7c7d09c1832c457e5e38aab6b44e9a8ed 100644 (file)
@@ -68,7 +68,6 @@ static void test_hello_reply(struct uloop_timeout *t)
        pipe(fds);
        ubus_request_set_fd(ctx, &req->req, fds[0]);
        ubus_complete_deferred_request(ctx, &req->req, 0);
-       close(fds[0]);
        req->fd = fds[1];
 
        req->timeout.cb = test_hello_fd_reply;
index bc054b8d0ff263a807482b48c093a6309ddcee72..030d38255c4193ad39db31256f6771975c7bf417 100644 (file)
@@ -142,6 +142,9 @@ int __hidden ubus_send_msg(struct ubus_context *ctx, uint32_t seq,
        if (ret < 0)
                ctx->sock.eof = true;
 
+       if (fd >= 0)
+               close(fd);
+
        return ret;
 }