From 3c6cd36c4ecfb4a6fb3fba6f04ee761c534fceac Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 17 Jan 2008 21:40:38 +0100 Subject: [PATCH 1/1] net.c: Fix a memory leak in makesock(). "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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net.c b/net.c index 2db34054..10fc1219 100644 --- 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; -- 2.39.2