uint64_t cookie;
if (buflen < sizeof(cookie)) {
- close_fd_array(fds, num_fds);
- return;
+ goto close_fds;
}
+
memcpy(&cookie, buf, sizeof(cookie));
buf += sizeof(cookie);
}
if (buflen < sizeof(hdr)) {
- close_fd_array(fds, num_fds);
- return;
+ goto close_fds;
}
memcpy(&hdr, buf, sizeof(hdr));
if (msg == NULL) {
msg = malloc(offsetof(struct unix_msg, buf) + hdr.msglen);
if (msg == NULL) {
- close_fd_array(fds, num_fds);
- return;
+ goto close_fds;
}
*msg = (struct unix_msg) {
.msglen = hdr.msglen,
space = msg->msglen - msg->received;
if (buflen > space) {
- close_fd_array(fds, num_fds);
- return;
+ goto close_fds;
}
memcpy(msg->buf + msg->received, buf, buflen);
msg->received += buflen;
if (msg->received < msg->msglen) {
- close_fd_array(fds, num_fds);
- return;
+ goto close_fds;
}
DLIST_REMOVE(ctx->msgs, msg);
ctx->recv_callback(ctx, msg->buf, msg->msglen, fds, num_fds, ctx->private_data);
free(msg);
+ return;
+
+close_fds:
+ close_fd_array(fds, num_fds);
}
int unix_msg_free(struct unix_msg_ctx *ctx)