diff --git a/nanoftp.c b/nanoftp.c
index f467e5a..2135ab9 100644
--- a/nanoftp.c
+++ b/nanoftp.c
@@ -908,6 +908,8 @@ xmlNanoFTPConnect(void *ctx) {
 	    return (-1);
 	}
 	if (tmp->ai_addrlen > sizeof(ctxt->ftpAddr)) {
+	    if (result)
+		freeaddrinfo (result);
 	    __xmlIOErr(XML_FROM_FTP, 0, "gethostbyname address mismatch");
 	    return (-1);
 	}
