]> granicus.if.org Git - psmisc/commitdiff
fuser: free local port before return
authorCraig Small <csmall@dropbear.xyz>
Mon, 2 Mar 2020 11:16:26 +0000 (22:16 +1100)
committerCraig Small <csmall@dropbear.xyz>
Mon, 2 Mar 2020 11:16:26 +0000 (22:16 +1100)
parse_inet allocated a string using strdup() but didn't always
release it.

References:
 Coverity #14401

src/fuser.c

index ac8244ac44c2928ef7e2896c78e7ab4ca6ac7b14..bbcbed22aa2ed9bb772e13fe1b0a7ee60005da94 100644 (file)
@@ -605,8 +605,10 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list)
                     getaddrinfo(NULL, lcl_port_str, &hints, &res)) != 0) {
                        fprintf(stderr, _("Cannot resolve local port %s: %s\n"),
                                lcl_port_str, gai_strerror(errcode));
+                       free(lcl_port_str);
                        return -1;
                }
+               free(lcl_port_str);
                if (res == NULL)
                        return -1;
                switch (res->ai_family) {
@@ -624,12 +626,10 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list)
                        fprintf(stderr, _("Unknown local port AF %d\n"),
                                res->ai_family);
                        freeaddrinfo(res);
-            free(lcl_port_str);
                        return -1;
                }
                freeaddrinfo(res);
        }
-       free(lcl_port_str);
        res = NULL;
        if (rmt_addr_str == NULL && rmt_port_str == NULL) {
                add_ip_conn(ip_list, protocol, this_name, ntohs(lcl_port), 0,