Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0b11d2

Browse files
committed
Fix memory leaks detecting in bug report #478003.
1 parent 0b66310 commit f0b11d2

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

Modules/getaddrinfo.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,14 @@ get_addr(hostname, af, res, pai, port0)
571571
error = EAI_FAIL;
572572
break;
573573
}
574-
goto bad;
574+
goto free;
575575
}
576576

577577
if ((hp->h_name == NULL) || (hp->h_name[0] == 0) ||
578-
(hp->h_addr_list[0] == NULL))
579-
ERR(EAI_FAIL);
578+
(hp->h_addr_list[0] == NULL)) {
579+
error = EAI_FAIL;
580+
goto free;
581+
}
580582

581583
for (i = 0; (ap = hp->h_addr_list[i]) != NULL; i++) {
582584
switch (af) {
@@ -632,7 +634,7 @@ get_addr(hostname, af, res, pai, port0)
632634
if (hp)
633635
freehostent(hp);
634636
#endif
635-
bad:
637+
/* bad: */
636638
*res = NULL;
637639
return error;
638640
}

Modules/socketmodule.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ setipaddr(char* name, struct sockaddr * addr_ret, int af)
606606
return -1;
607607
}
608608
if (res->ai_next) {
609+
freeaddrinfo(res);
609610
PyErr_SetString(PySocket_Error,
610611
"wildcard resolved to multiple address");
611612
return -1;
@@ -2461,7 +2462,8 @@ PySocket_inet_ntoa(PyObject *self, PyObject *args)
24612462
static PyObject *
24622463
PySocket_getaddrinfo(PyObject *self, PyObject *args)
24632464
{
2464-
struct addrinfo hints, *res0, *res;
2465+
struct addrinfo hints, *res;
2466+
struct addrinfo *res0 = NULL;
24652467
PyObject *pobj = (PyObject *)NULL;
24662468
char pbuf[30];
24672469
char *hptr, *pptr;
@@ -2522,6 +2524,8 @@ PySocket_getaddrinfo(PyObject *self, PyObject *args)
25222524
err:
25232525
Py_XDECREF(single);
25242526
Py_XDECREF(all);
2527+
if (res0)
2528+
freeaddrinfo(res0);
25252529
return (PyObject *)NULL;
25262530
}
25272531

0 commit comments

Comments
 (0)