swrap: Do not leak memory in swrap_recvmsg_after().
authorAndreas Schneider <asn@samba.org>
Thu, 8 May 2014 12:04:11 +0000 (14:04 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 9 May 2014 07:03:33 +0000 (09:03 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Reviewed-by: Simo Sorce <idra@samba.org>
lib/socket_wrapper/socket_wrapper.c

index c5b1fdf85e00bdfce5e672bd2e7caf8117695950..5ed9d9fa7306f583dc24915ad3332b39530508a5 100644 (file)
@@ -3155,7 +3155,7 @@ static int swrap_recvmsg_after(int fd,
 {
        int saved_errno = errno;
        size_t i;
-       uint8_t *buf;
+       uint8_t *buf = NULL;
        off_t ofs = 0;
        size_t avail = 0;
        size_t remain;
@@ -3187,7 +3187,7 @@ static int swrap_recvmsg_after(int fd,
 
        /* we capture it as one single packet */
        buf = (uint8_t *)malloc(remain);
-       if (!buf) {
+       if (buf == NULL) {
                /* we just not capture the packet */
                errno = saved_errno;
                return -1;
@@ -3228,7 +3228,7 @@ static int swrap_recvmsg_after(int fd,
                                                      msg->msg_name,
                                                      &msg->msg_namelen);
                        if (rc == -1) {
-                               return -1;
+                               goto done;
                        }
 
                        swrap_dump_packet(si,
@@ -3247,6 +3247,7 @@ static int swrap_recvmsg_after(int fd,
                break;
        }
 
+done:
        free(buf);
        errno = saved_errno;
        return 0;