ubus: Remove unnecessary memset calls.
[project/ubus.git] / ubusd.c
diff --git a/ubusd.c b/ubusd.c
index 7279a70..f060b38 100644 (file)
--- a/ubusd.c
+++ b/ubusd.c
 
 static struct ubus_msg_buf *ubus_msg_ref(struct ubus_msg_buf *ub)
 {
-       if (ub->refcount == ~0)
-               return ubus_msg_new(ub->data, ub->len, false);
+       struct ubus_msg_buf *new_ub;
+       if (ub->refcount == ~0) {
+               new_ub = ubus_msg_new(ub->data, ub->len, false);
+               if (!new_ub)
+                       return NULL;
+               memcpy(&new_ub->hdr, &ub->hdr, sizeof(struct ubus_msghdr));
+               new_ub->fd = ub->fd;
+               return new_ub;
+       }
 
        ub->refcount++;
        return ub;
@@ -148,12 +155,13 @@ void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub, bool free)
 
        if (!cl->tx_queue[cl->txq_cur]) {
                written = ubus_msg_writev(cl->sock.fd, ub, 0);
-               if (written >= ub->len + sizeof(ub->hdr))
-                       goto out;
 
                if (written < 0)
                        written = 0;
 
+               if (written >= ub->len + sizeof(ub->hdr))
+                       goto out;
+
                cl->txq_ofs = written;
 
                /* get an event once we can write to the socket again */