staging: usbip: userspace: avoid memory leaks
authorStefan Reif <ke42caxa@cip.cs.fau.de>
Thu, 4 Apr 2013 14:03:12 +0000 (16:03 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Apr 2013 21:22:51 +0000 (14:22 -0700)
Call freeaddrinfo when connect/listen fails.
Call usbip_host_driver_close on error.

Signed-off-by: Stefan Reif <ke42caxa@cip.cs.fau.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/usbip/userspace/src/usbip_network.c
drivers/staging/usbip/userspace/src/usbipd.c

index 4cb76e5..b12448e 100644 (file)
@@ -248,10 +248,10 @@ int usbip_net_tcp_connect(char *hostname, char *service)
                close(sockfd);
        }
 
+       freeaddrinfo(res);
+
        if (!rp)
                return EAI_SYSTEM;
 
-       freeaddrinfo(res);
-
        return sockfd;
 }
index cc3be17..3f10c51 100644 (file)
@@ -448,6 +448,7 @@ static int do_standalone_mode(int daemonize)
        if (daemonize) {
                if (daemon(0, 0) < 0) {
                        err("daemonizing failed: %s", strerror(errno));
+                       usbip_host_driver_close();
                        return -1;
                }
                umask(0);
@@ -456,14 +457,18 @@ static int do_standalone_mode(int daemonize)
        set_signal();
 
        ai_head = do_getaddrinfo(NULL, PF_UNSPEC);
-       if (!ai_head)
+       if (!ai_head) {
+               usbip_host_driver_close();
                return -1;
+       }
 
        info("starting " PROGNAME " (%s)", usbip_version_string);
 
        nsockfd = listen_all_addrinfo(ai_head, sockfdlist);
        if (nsockfd <= 0) {
                err("failed to open a listening socket");
+               freeaddrinfo(ai_head);
+               usbip_host_driver_close();
                return -1;
        }
        fds = calloc(nsockfd, sizeof(struct pollfd));