]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
net.c: Fix a memory leak in makesock().
authorAndre Noll <maan@systemlinux.org>
Thu, 17 Jan 2008 20:40:38 +0000 (21:40 +0100)
committerAndre Noll <maan@systemlinux.org>
Thu, 17 Jan 2008 20:40:38 +0000 (21:40 +0100)
"port" was allocated dynamically but never freed. Fix it by
using a static buffer instead. This buffer can not overflow as
"port_number" is an unsigned short, so its decimal representation
consists of at most 5 digits.

net.c

diff --git a/net.c b/net.c
index 2db340542d4f78531b6d4af4909d6fdc8eb1ce91..10fc121912b8d242b7ca15a8081c2e7e490e44c5 100644 (file)
--- a/net.c
+++ b/net.c
@@ -147,10 +147,11 @@ int makesock(unsigned l3type, unsigned l4type, int passive,
 {
        struct addrinfo *local = NULL, *src,
                        *remote = NULL, *dst, hints;
-       char            *port = make_message("%u", port_number);
        int             rc, on = 1, sockfd = -1,
                        socktype = sock_type(l4type);
+       char port[6]; /* port number has at most 5 digits */
 
+       sprintf(port, "%u", port_number);
        /* Set up address hint structure */
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = l3type;