roken: fix theoretical leak introduced in 7fbe7be6
authorLuke Howard <lukeh@padl.com>
Thu, 23 Sep 2021 00:32:45 +0000 (10:32 +1000)
committerLuke Howard <lukeh@padl.com>
Thu, 23 Sep 2021 00:32:45 +0000 (10:32 +1000)
split_spec() should free output parameters if it fails. This was not a leak in
practice because its single caller cleaned up anyway, but cleaning up for good
hygiene.

lib/roken/roken_gethostby.c

index f7b5086c400f4220a21b54797b4621b37241d03f..a2febd0d169054095b5d42aa2867fdc7b654803a 100644 (file)
@@ -102,8 +102,11 @@ split_spec(const char *spec, char **host, int *port, char **path, int def_port)
     if(p) {
        if(path) {
            *path = strdup(p);
-           if (*path == NULL)
+           if (*path == NULL) {
+               free(*host);
+               *host = NULL;
                return -1;
+           }
        }
        *p = '\0';
     }else