Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.84k stars 524 forks source link

Odd memory leak #1104

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

Migrated from rt.perl.org#2058 (status was 'resolved')

Searchable as RT2058$

p5pRT commented 24 years ago

From gerti@bitart.com

Created by gerti@bitart.com

The short program below leaks under various versions of perl and on various OS. Am I missing something\, or is this a bug in perl?

Thanks!

$x="TST00000"; while(1) {   my $handle=$x++;   open($handle\,'/etc/rc'); # or any other file   close($handle); }

Perl Info ``` Site configuration information for perl 5.00502: Configured by gerti at Tue Mar 23 16:36:15 CST 1999. Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration: Platform: osname=next, osvers=3_3, archname=i386-next uname='camelot ' hint=recommended, useposix=true, d_sigaction=undef usethreads=undef useperlio=undef d_sfio=undef Compiler: cc='cc', optimize='-O', gccversion=NeXT DevKit-based CPP 3.1 cppflags='-DUSE_NEXT_CTYPE -I/usr/local/include' ccflags ='-DUSE_NEXT_CTYPE -I/usr/local/include' stdchar='char', d_stdstdio=define, usevfork=false intsize=4, longsize=4, ptrsize=4, doublesize=8 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags ='-u libsys_s -L/usr/local/lib' libpth=/usr/local/lib /usr/shlib /lib /usr/lib libs=-ldbm libc=/lib/libsys_s.a, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_next.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-nostdlib -r -L/usr/local/lib' Locally applied patches: @INC for perl 5.00502: /theUsers/gerti/Unix/lib/perl5 /theUsers/gerti/Clients/Interfax/Distribution/INFax.3/lib /usr/local/lib/perl5/5.00502/i386-next /usr/local/lib/perl5/5.00502 /usr/local/lib/perl5/site_perl/5.005/i386-next /usr/local/lib/perl5/site_perl/5.005 . Environment for perl 5.00502: HOME=/theUsers/gerti LANG (unset) LD_LIBRARY_PATH=/usr/lib:/usr/local/lib LOGDIR (unset) PATH=.:/etc:/usr/etc:/theUsers/gerti/Unix/bin:/usr/local/bin:/usr/local/netpbm/bin:/usr/ucb:/bin:/usr/bin:/usr/sybase/bin:/theUsers/gerti/Apps:/LocalApps:/NextApps:/NextAdmin:/NextDeveloper/Demos:/usr/local/bin/ezmlm PERL5LIB=/theUsers/gerti/Unix/lib/perl5:/theUsers/gerti/Clients/Interfax/Distribution/INFax.3/lib PERL_BADLANG (unset) SHELL=/usr/bin/zsh ```
p5pRT commented 24 years ago

From @gsar

On 31 Jan 2000 07​:46​:24 GMT\, gerti@​bitart.com wrote​:

The short program below leaks under various versions of perl and on various OS. Am I missing something\, or is this a bug in perl?

Thanks!

$x="TST00000"; while(1) { my $handle=$x++; open($handle\,'/etc/rc'); # or any other file close($handle); }

You're filling up the symbol table with empty symbols (closed filehandles). Create anonymous symbols with Symbol instead.

  use Symbol;   while (1) {   open(my $handle = gensym\, '/etc/rc') or die;   close $handle;   }

In 5.6\, you'll be able to shorten that to​:

  while (1) {   open my $handle\, '/etc/rc' or die;   close $handle;   }

Sarathy gsar@​ActiveState.com