develooper Front page | perl.perl5.porters | Postings from May 2003

[perl #22071] socketpair() leaks memory

Thread Next
May 1, 2003 05:52
[perl #22071] socketpair() leaks memory
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #22071]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.34 running under perl v5.8.0.

[Please enter your report here]

Socketpair() allocates 4 buffers (I assume that's one input and one output
buffer for each socket) but it only frees 1 of them when each socket is
closed, leaving 2 unused buffers behind. If you just create the socketpair
and close the sockets without using them, it doesn't leak as fast (buffers
are lazy-allocated when used?)

This demo program shows the leak, with minimal use of modules (to prove that
the leak is really in the core).

The leak appears to be new - I can't reproduce it in 5.6.1, but that might be
because I don't have perlio enabled on the 5.6.1.

#!/usr/bin/perl -w
use strict;
use Socket; # Only for AF_UNIX and SOCK_STREAM!

for(my $i=0;;++$i) {
  socketpair(SOCK1, SOCK2, AF_UNIX, SOCK_STREAM, 0);
    select(SOCK1); $|=1; select(STDOUT);
    print SOCK1 "$i\r";
    print STDOUT scalar <SOCK2>;
  } else {
    print "$i\r";
  # On my machine, the following gives a report on memory usage of the perl
  # process after every 100th iteration, which demonstrates constant growth.
  #print("\n"), system("ps mp$$") unless $i % 100;

[Please do not change anything below this line]
Site configuration information for perl v5.8.0:

Configured by pacman at Fri Apr 25 21:52:06 EST 2003.

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
    osname=linux, osvers=2.2.20, archname=i386-linux
    uname='linux gkar 2.2.20 #1 sat apr 20 11:45:28 est 2002 i586 unknown '
    config_args='-Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i386-linux -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8.0 -Darchlib=/usr/lib/perl/5.8.0 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.0 -Dsitearch=/usr/local/lib/perl/5.8.0 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Duseshrplib -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='cc', ccflags ='-DDEBIAN -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    cppflags='-DDEBIAN -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='2.95.4 20011002 (Debian prerelease)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldbm -ldb -ldl -lm -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
    libc=/lib/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl/5.8.0/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:

@INC for perl v5.8.0:

Environment for perl v5.8.0:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About