Fix memory leaks detecting in bug report #478003.
diff --git a/Modules/getaddrinfo.c b/Modules/getaddrinfo.c
index 5d137d8..5d92608 100644
--- a/Modules/getaddrinfo.c
+++ b/Modules/getaddrinfo.c
@@ -571,12 +571,14 @@
 			error = EAI_FAIL;
 			break;
 		}
-		goto bad;
+		goto free;
 	}
 
 	if ((hp->h_name == NULL) || (hp->h_name[0] == 0) ||
-	    (hp->h_addr_list[0] == NULL))
-		ERR(EAI_FAIL);
+	    (hp->h_addr_list[0] == NULL)) {
+		error = EAI_FAIL;
+		goto free;
+	}
 	
 	for (i = 0; (ap = hp->h_addr_list[i]) != NULL; i++) {
 		switch (af) {
@@ -632,7 +634,7 @@
 	if (hp)
 		freehostent(hp);
 #endif
- bad:
+/* bad: */
 	*res = NULL;
 	return error;
 }
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index fea6b85..601880e 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -606,6 +606,7 @@
 			return -1;
 		}
 		if (res->ai_next) {
+			freeaddrinfo(res);
 			PyErr_SetString(PySocket_Error,
 				"wildcard resolved to multiple address");
 			return -1;
@@ -2461,7 +2462,8 @@
 static PyObject *
 PySocket_getaddrinfo(PyObject *self, PyObject *args)
 {
-	struct addrinfo hints, *res0, *res;
+	struct addrinfo hints, *res;
+	struct addrinfo *res0 = NULL;
 	PyObject *pobj = (PyObject *)NULL;
 	char pbuf[30];
 	char *hptr, *pptr;
@@ -2522,6 +2524,8 @@
  err:
 	Py_XDECREF(single);
 	Py_XDECREF(all);
+	if (res0)
+		freeaddrinfo(res0);
 	return (PyObject *)NULL;
 }