]> granicus.if.org Git - python/commitdiff
Fix memory leaks detecting in bug report #478003.
authorMartin v. Löwis <martin@v.loewis.de>
Wed, 7 Nov 2001 08:31:03 +0000 (08:31 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Wed, 7 Nov 2001 08:31:03 +0000 (08:31 +0000)
Modules/getaddrinfo.c
Modules/socketmodule.c

index 5d137d8340587a47f42093f8448adf17c9091200..5d92608df6977dfb3b83e98993b854e0b63110a1 100644 (file)
@@ -571,12 +571,14 @@ get_addr(hostname, af, res, pai, port0)
                        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 @@ get_addr(hostname, af, res, pai, port0)
        if (hp)
                freehostent(hp);
 #endif
- bad:
+/* bad: */
        *res = NULL;
        return error;
 }
index fea6b85b392619b3f3ea0114ff894535c245a005..601880e56540b35fae0b24128f44d461cc1019e7 100644 (file)
@@ -606,6 +606,7 @@ setipaddr(char* name, struct sockaddr * addr_ret, int af)
                        return -1;
                }
                if (res->ai_next) {
+                       freeaddrinfo(res);
                        PyErr_SetString(PySocket_Error,
                                "wildcard resolved to multiple address");
                        return -1;
@@ -2461,7 +2462,8 @@ PySocket_inet_ntoa(PyObject *self, PyObject *args)
 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 @@ PySocket_getaddrinfo(PyObject *self, PyObject *args)
  err:
        Py_XDECREF(single);
        Py_XDECREF(all);
+       if (res0)
+               freeaddrinfo(res0);
        return (PyObject *)NULL;
 }