Hello,
       Im experiencing a memory leak problem with my Net::LDAP. It may be
due to me not properly destroying the $ldap object? I checked previous
mailings and tried to use the old suggstions.
The code I used to test is attached at end of mail.

When started I used top to see the memory used...

   PID USERNAME THR PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
 12808 root       1  18    0 5584K 5016K sleep    0:00  0.64%
test_propper_ca

Then I hit Enter once to loop it 50000 times. and the memory SIZE used
increased to.... 10MB

   PID USERNAME THR PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
 12808 root       1   0    0   10M 9944K sleep    4:38 50.37%
test_propper_ca


When I comment out the lines in the scrpt between my # Memory Leak comments,
I do not get the leak.

Is $ldap->unbind; enough to destroy the object? Do I need to do something
more?

Im using Solaris 8, and have compiled Perl 5.8.0 and installed following
modules...
  perl-ldap-0.28.tar.gz
  Authen::SASL  -> Authen-SASL-2.04.tar.gz
  IO::Socket::SSL -> IO-Socket-SSL-0.92.tar.gz
       Net::SSLeay  -> Net_SSLeay.pm-1.23.tar.gz    -> needs OpenSSL-0.9.6.b
or newer.
  URI::ldap  -> URI-1.23.tar.gz
  Convert::ASN1  -> Convert-ASN1-0.17.tar.gz


Your help is greatly appreciated,

Steve.
----------
Steven Carr,
ISP Engineering,
[EMAIL PROTECTED]


####################################Code: ####################
#!/opt/perl5.8.0/bin/perl

use Net::LDAP;
use Net::LDAP::Constant qw(LDAP_SUCCESS LDAP_COMPARE_TRUE
LDAP_COMPARE_FALSE);
use strict;

my $LDAPServerAddress = 'ldap-be-01';   # You should define this value
my $BASE_DN           = "ou=ishmail,dc=ish,dc=de";

my $a=0;
my $errorMsg;

while(<STDIN>) {
  for(my $i=0;$i<50000;$i++)
  {
     if( ($i%2) == 0)
     {
        # Try a correct password
        $errorMsg = checkPassword('[EMAIL PROTECTED]','secret');
     } else {
        # Try a wrong password
        $errorMsg = checkPassword('[EMAIL PROTECTED]','basspaddws');
     }
     $a++;
     print "TRY: $a\n";
  }
}

###########################################################################

sub checkPassword() {
  my ($user,$password)[EMAIL PROTECTED];

  my $name="";
  my $domain="";

  if($user =~ /(.+)\@(.+)/) {
    $name=$1;
    $domain=$2;
  } else {
    return "Full account name with \@ and domain part expected";
  }

 ######## Leak happens here...

  my $ldap = Net::LDAP->new($LDAPServerAddress,port=>389,timeout=>20);
  if(!defined ($ldap))
  {
    return "Can't connect to $LDAPServerAddress via LDAP";
  }

  $ldap->{net_ldap_mesg}="";              # Try and stop mem leak?
  $ldap->unbind;                        # unbind & disconnect
  close $ldap->socket;                  # Try and stop mem leak?
 #######  End of Leak marker...

  return undef;                           # return "undef" on success
}

Reply via email to