Skip Menu |

This queue is for tickets about the Win32-Console CPAN distribution.

Report information
The Basics
Id: 53264
Status: open
Priority: 0/
Queue: Win32-Console

People
Owner: Nobody in particular
Requestors: RCAPUTO [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



Subject: Memory leak in _SetStdHandle() in child process
This test program quickly leaks memory, as can be seen in the Task Manager. #!perl use warnings; use strict; use Win32::Console; use Win32API::File qw(FdGetOsFHandle); TRY: while (1) { my $pid = fork(); # fork() failed. next TRY unless defined $pid; # Parent. if ($pid) { # Wait for child. waitpid($pid, 0); next TRY; } # Child. Win32::Console::_SetStdHandle( STD_INPUT_HANDLE(), FdGetOsFHandle(fileno(STDIN)) ); exit(0); }
1) _SetStdHandle is an internal, undocumented method and should not be used directly.
2) the leak is not in _SetStdHandle, which is a pure wrapper around the Win32 API of the same name. it is instead in the STD_INPUT_HANDLE() constant call. 

the same behaviour can be observed with constants from other modules:

Show quoted text
#!perl

use warnings;
use strict;

use Win32::File;
use Win32API::File qw(FdGetOsFHandle);

TRY: while (1) {
  my $pid = fork();

  # fork() failed.
  next TRY unless defined $pid;

  # Parent.
  if ($pid) {
    # Wait for child.
    waitpid($pid, 0);
    next TRY;
  }

  # Child.
  print READONLY();
  exit(0);
}

I don't know if this is due to the XS constant wrapper, or AUTOLOAD, or what else, but for sure there's something wrong somewhere.

as a workaround, use:

my $std_input_handle = STD_INPUT_HANDLE();

before the loop, and use $std_input_handle in the child code.

cheers,
Aldo