cURL / Mailing Lists / curl-users / Single Mail

curl-users

Problem if the supported data for CURLOPT_URL goes out of scope (perl bindings)

From: Erik Wasser <erik.wasser_at_iquer.net>
Date: Tue, 21 Nov 2006 14:19:56 +0100

Hello list curl-users_at_cool.haxx.se,

I've a problem with the perl binding and I would like to hear other
opinions about this issue. (I'm testing with WWW::Curl::Easy 3.01 and
perl v5.8.8 built for i686-linux.)

It seems that the perl binding got a problem if the supported URL for
the option CURLOPT_URL gets out of scope.

Here's a small example:

my $curl = WWW::Curl::Easy->new();

{
   my $ref = { dombot => 'http://www.google.de' };

   $curl->setopt(CURLOPT_URL, $ref->{dombot});
}
# $ref goes out of scope

$curl->perform() && die $curl->errbuf();

The error message looks like if it contains some garbage of the
memory: "Couldn't resolve host 'À'".

The script below will give you a complete sample script to execute. Just
change the 'BUG' constant at the top of the program.

#!/usr/bin/perl -w

use strict;
use warnings;

use constant BUG => 1;

use WWW::Curl::Easy;

my $curl = WWW::Curl::Easy->new();

my $body = "";

$curl->setopt(CURLOPT_WRITEFUNCTION, sub {
   my $chunk = shift;

   $body .= $chunk;

   return length($chunk);
});

# This scope is needed. Without it the program
# runs fine.
{
   my $ref = { dombot => 'http://www.google.de' };

   if (BUG)
   {
      $curl->setopt(CURLOPT_URL, $ref->{dombot});
   }
   else
   {
      my $dummy = $ref->{dombot};
      $curl->setopt(CURLOPT_URL, $dummy);
   }
}

$curl->perform() && die $curl->errbuf();

printf "OK, %d bytes fetched\n", length($body);

-- 
So long... Fuzz
Received on 2006-11-21