summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-02-05 09:46:15 (GMT)
committerGuido van Rossum <guido@python.org>1993-02-05 09:46:15 (GMT)
commit6f5afc9a73d7388bf96df69323589f2f82c110ba (patch)
treef642f4a5f0d1a136b4480575460662deb89d7502 /Modules/socketmodule.c
parent995c33a2bbb540729e3330ed8f11365e578ab5a0 (diff)
downloadcpython-6f5afc9a73d7388bf96df69323589f2f82c110ba.zip
cpython-6f5afc9a73d7388bf96df69323589f2f82c110ba.tar.gz
cpython-6f5afc9a73d7388bf96df69323589f2f82c110ba.tar.bz2
* ceval.c: ifdef out the last argument passing compat hack.
* Fixed memory leaks in socket, select and sv modules: mkvalue("O", v) does INCREF(v) so if v is brand new it should be XDECREF'd
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index c72c9fd..2a0e291 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -223,7 +223,10 @@ makesockaddr(addr, addrlen)
case AF_INET:
{
struct sockaddr_in *a = (struct sockaddr_in *) addr;
- return mkvalue("Oi", makeipaddr(a), ntohs(a->sin_port));
+ object *addr = makeipaddr(a);
+ object *ret = mkvalue("Oi", addr, ntohs(a->sin_port));
+ XDECREF(addr);
+ return ret;
}
case AF_UNIX:
@@ -342,7 +345,7 @@ sock_accept(s, args)
{
char addrbuf[256];
int addrlen, newfd;
- object *res;
+ object *sock, *addr, *res;
if (!getnoarg(args))
return NULL;
if (!getsockaddrlen(s, &addrlen))
@@ -354,13 +357,16 @@ sock_accept(s, args)
return socket_error();
/* Create the new object with unspecified family,
to avoid calls to bind() etc. on it. */
- res = mkvalue("OO", (object *) newsockobject(newfd,
- s->sock_family,
- s->sock_type,
- s->sock_proto),
- makesockaddr((struct sockaddr *) addrbuf, addrlen));
- if (res == NULL)
+ sock = (object *) newsockobject(newfd,
+ s->sock_family,
+ s->sock_type,
+ s->sock_proto);
+ if (sock == NULL)
close(newfd);
+ addr = makesockaddr((struct sockaddr *) addrbuf, addrlen);
+ res = mkvalue("OO", sock, addr);
+ XDECREF(sock);
+ XDECREF(addr);
return res;
}
@@ -693,7 +699,7 @@ sock_recvfrom(s, args)
object *args;
{
char addrbuf[256];
- object *buf;
+ object *buf, *addr, *ret;
int addrlen, len, n;
if (!getintarg(args, &len))
return NULL;
@@ -708,8 +714,11 @@ sock_recvfrom(s, args)
return socket_error();
if (resizestring(&buf, n) < 0)
return NULL;
- return mkvalue("OO", buf,
- makesockaddr((struct sockaddr *)addrbuf, addrlen));
+ addr = makesockaddr((struct sockaddr *)addrbuf, addrlen);
+ ret = mkvalue("OO", buf, addr);
+ XDECREF(addr);
+ XDECREF(buf);
+ return ret;
}