mogul has asked for the wisdom of the Perl Monks concerning the following question:

While fiddling with some SNMP code I stumbled across a leak or something. Example code: (yes, I know it will never get anything with Timeout=>0)
#!/usr/bin/perl use strict; use warnings; use SNMP; use Data::Dumper; main(); sub main { for my $item ('something that leaks', 'more leaking stuff') { doit(); } } sub doit { my $session = new SNMP::Session(DestHost => '127.0.0.1', Community => 'DoesNotWork', Timeout => 0, Version => '2c'); my $x = $session->bulkwalk(0, 1, ['.1.3.6.1.2.1.1.1']); die 'DUMP IT: ' . Dumper \$x; }
and the output:
DUMP IT: $VAR1 = \[ 'something that leaks', 'more leaking stuff', undef ];
How did those two constants end up in the output?
os: kubuntu-10.04 perl: v5.10.1 libsnmp-perl: 5.4.2.1~dfsg0ubuntu1-0ubuntu2.1

Replies are listed 'Best First'.
Re: Something is leaking
by dave_the_m (Monsignor) on Mar 05, 2011 at 20:48 UTC
    Looks most likely a bug in Net::SMTP that's corrupting the stack

    Dave.

      Hmm, it was what I feared. I'l see if I can find somewhere to file a bug report.

      Thanks for your time, all of you!

        Did you mean Net::SNMP instead
        A brain fart! Presumably I meant the SNMP module.

        Dave.

Re: Something is leaking
by Khen1950fx (Canon) on Mar 05, 2011 at 20:19 UTC
    Those two constants ended up in the output because you used for. I would use unless instead.
    #!/usr/bin/perl use strict; use warnings; use SNMP; use Data::Dumper; my $hostname = '127.0.0.1'; my $community = 'DoesNotWork'; $SNMP::verbose = 1; $SNMP::debugging = 1; main(); sub main { my @item =('something that leaks', 'more leaking stuff'); unless (not @item) { doit(); } } sub doit { my $session = new SNMP::Session('DestHost' => $hostname, 'Community' => $community, 'Timeout' => 0, 'Version' => '2c'); my $x = $session->bulkwalk(0, 1, ['.1.3.6.1.2.1.1.1']); warn 'DUMP IT: ' . Dumper(\$x); }

      What do you think is happening in the OP's code and how does your change fix the problem?

      True laziness is hard work
        I was thinking that the OP wanted a test failure, so I tried reversing the sense of the test to get around the freed value warning. How would you handle it? Thanks for the response.
      No no, my whole point was not to touch or use $item or any of the two constants after their declaration.

      And still they get printed.