fix invalid close() call
authorJohn Crispin <john@phrozen.org>
Wed, 3 Jan 2018 10:52:56 +0000 (11:52 +0100)
committerJohn Crispin <john@phrozen.org>
Wed, 17 Jan 2018 08:58:54 +0000 (09:58 +0100)
valgrind complained about this one

==18632== Warning: invalid file descriptor -1 in syscall close()
==18632==    at 0x5326D20: __close_nocancel (syscall-template.S:84)
==18632==    by 0x5046C02: ubus_process_invoke (libubus-obj.c:98)
==18632==    by 0x5046DC3: ubus_process_obj_msg (libubus-obj.c:142)
==18632==    by 0x5045E98: ubus_process_msg (libubus.c:106)
==18632==    by 0x50468D0: ubus_handle_data (libubus-io.c:314)
==18632==    by 0x4E3D125: uloop_run_events (uloop.c:198)
==18632==    by 0x4E3D125: uloop_run_timeout (uloop.c:555)
==18632==    by 0x109BEF: uloop_run (uloop.h:111)
==18632==    by 0x109BEF: main (main.c:25)

Signed-off-by: John Crispin <john@phrozen.org>
libubus-obj.c

index 9261b83246f26ea83167659970f71f504fa2df24..b3019652c52d73a1f9e1c6d24abb821161f2a198 100644 (file)
@@ -95,7 +95,8 @@ found:
        ret = obj->methods[method].handler(ctx, obj, &req,
                                           blob_data(attrbuf[UBUS_ATTR_METHOD]),
                                           attrbuf[UBUS_ATTR_DATA]);
-       close(req.req_fd);
+       if (req.req_fd >= 0)
+               close(req.req_fd);
        if (req.deferred || no_reply)
                return;