libcody: Avoid double-free
authorJonathan Wakely <jwakely@redhat.com>
Thu, 21 Oct 2021 13:17:43 +0000 (14:17 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 21 Oct 2021 21:23:00 +0000 (22:23 +0100)
If the listen call fails then 'goto fail' will jump to that label and
use freeaddrinfo again. Set the pointer to null to prevent that.

libcody/ChangeLog:

* netserver.cc (ListenInet6): Set pointer to null after
deallocation.

libcody/netserver.cc

index 30202c5..0499b57 100644 (file)
@@ -140,6 +140,7 @@ int ListenInet6 (char const **e, char const *name, int port, unsigned backlog)
 
  listen:;
   freeaddrinfo (addrs);
+  addrs = nullptr;
 
   if (listen (fd, backlog ? backlog : 17) < 0)
     {