cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Memory leak

From: Vijay <nags.vijay_at_gmail.com>
Date: Wed, 22 Oct 2008 20:36:47 +0530

That is the only difference am having in my code.
If i reuse the connection no leak at all.
Doing reinitializing before that am cleaning also.
Tried the option suggested by you doing global init only once

Linux buildsrv 2.4.21-15.0.3.ELsmp #1 SMP Tue Jun 29 18:04:47 EDT 2004 i686
i686 i386 GNU/Linux
curl - curl-7.18.0

On Wed, Oct 22, 2008 at 12:50 AM, <curl-library-request_at_cool.haxx.se> wrote:

> Send curl-library mailing list submissions to
> curl-library_at_cool.haxx.se
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-library
> or, via email, send a message with subject or body 'help' to
> curl-library-request_at_cool.haxx.se
>
> You can reach the person managing the list at
> curl-library-owner_at_cool.haxx.se
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of curl-library digest..."
>
>
> Today's Topics:
>
> 1. Re: question regarding CURLOPT_WRITEFUNCTION &
> CURLOPT_WRITEDATA (Jan)
> 2. Re: question regarding CURLOPT_WRITEFUNCTION &
> CURLOPT_WRITEDATA (Nikolai Kondrashov)
> 3. Memory leak (Vijay)
> 4. Re: question regarding CURLOPT_WRITEFUNCTION &
> CURLOPT_WRITEDATA (Jan)
> 5. Re: Memory leak (Daniel Stenberg)
> 6. Re: Debug code introduced... (Mohun Biswas)
> 7. Re: question regarding CURLOPT_WRITEFUNCTION &
> CURLOPT_WRITEDATA (Ralph Mitchell)
> 8. Re: transfer closed with outstanding read data remaining with
> Expect: 100-continue (Emanuel Norrbin)
> 9. SSL and basic authentication. (Josef Wolf)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 21 Oct 2008 12:16:01 +0200
> From: Jan <haihappn_at_gmail.com>
> Subject: Re: question regarding CURLOPT_WRITEFUNCTION &
> CURLOPT_WRITEDATA
> To: "libcurl development" <curl-library_at_cool.haxx.se>
> Message-ID:
> <712839f60810210316v2c589e96mab37fc2f05cb475a_at_mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Thanks guys, it works - at least for web pages. when i try to grab a jpg
> file with that example program, it doesnt work... i only get a small chunk,
> which does not represent that image.
> any ideas for this?
>
> --
> Jan
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://cool.haxx.se/pipermail/curl-library/attachments/20081021/5c9f6620/attachment.htm
> >
>
> ------------------------------
>
> Message: 2
> Date: Tue, 21 Oct 2008 14:28:29 +0400
> From: Nikolai Kondrashov <Nikolai.Kondrashov_at_oktetlabs.ru>
> Subject: Re: question regarding CURLOPT_WRITEFUNCTION &
> CURLOPT_WRITEDATA
> To: libcurl development <curl-library_at_cool.haxx.se>
> Message-ID: <48FDAECD.1090907_at_oktetlabs.ru>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Jan wrote:
> > Thanks guys, it works - at least for web pages. when i try to grab a jpg
> > file with that example program, it doesnt work... i only get a small
> > chunk, which does not represent that image.
> > any ideas for this?
> Are you interpreting it as a zero-terminated string?
>
> Sincerely,
> Nick
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 21 Oct 2008 16:36:04 +0530
> From: Vijay <nags.vijay_at_gmail.com>
> Subject: Memory leak
> To: curl-library_at_cool.haxx.se
> Message-ID:
> <2549ebb10810210406w22baf1f5j982f00f9772478c_at_mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> For each and every http query am using a new connection,
> So what am doing in my code is
>
> //Close the connection
> curl_easy_cleanup(m_ptrCurl);
> //curl_free(m_ptrCurl);
> curl_global_cleanup();
> //Reinitialize for next request in advace anyway connection wont be
> //created unless new request comes
> ReInitialize();
>
> In Reinitalize am doing
> if (CURL_OPERATION_OK != curl_global_init(CURL_GLOBAL_ALL))
> {
> LogClient::GetInstance()->Log(LOG_CATEGORY_ERROR,"LibCurl global
> initialization failed. so exiting ");
> return HTTPAGENT_FAILURE;
> }
>
> m_ptrCurl = curl_easy_init();
>
> if(NULL == m_ptrCurl)
> {
> LogClient::GetInstance()->Log(LOG_CATEGORY_ERROR,"LibCurl easy
> initialization failed. so exiting ");
> return HTTPAGENT_FAILURE;
>
> }
> Will it cause any memory leak.
>
> Because of these am getting memory leak in my code.
> Suggest me what to do
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://cool.haxx.se/pipermail/curl-library/attachments/20081021/c7706a66/attachment.htm
> >
>
> ------------------------------
>
> Message: 4
> Date: Tue, 21 Oct 2008 13:22:25 +0200
> From: Jan <haihappn_at_gmail.com>
> Subject: Re: question regarding CURLOPT_WRITEFUNCTION &
> CURLOPT_WRITEDATA
> To: "libcurl development" <curl-library_at_cool.haxx.se>
> Message-ID:
> <712839f60810210422v743dbb82m3de5041b73eb8439_at_mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> 2008/10/21 Nikolai Kondrashov <Nikolai.Kondrashov_at_oktetlabs.ru>
>
>
> > Are you interpreting it as a zero-terminated string?
> >
>
> Well, i think so, because the struct uses a char pointer to store the
> content of the chunk. the solution would be to change the struct in a way
> so
> that it accepts also binary data, but it dont exactly know how to do this..
>
> --
> Jan
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://cool.haxx.se/pipermail/curl-library/attachments/20081021/49841b11/attachment.htm
> >
>
> ------------------------------
>
> Message: 5
> Date: Tue, 21 Oct 2008 13:22:20 +0200 (CEST)
> From: Daniel Stenberg <daniel_at_haxx.se>
> Subject: Re: Memory leak
> To: libcurl development <curl-library_at_cool.haxx.se>
> Message-ID: <alpine.LRH.1.10.0810211319260.23402_at_yvahk3.pbagnpgbe.fr>
> Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII
>
> On Tue, 21 Oct 2008, Vijay wrote:
>
> > //Close the connection
> > curl_easy_cleanup(m_ptrCurl);
> > //curl_free(m_ptrCurl);
> > curl_global_cleanup();
>
> curl_global_cleanup is a global cleanup (and the corresponding
> curl_global_init) that should only ever be done once your program is done
> using libcurl. Using them in a loop of any kind is wrong.
>
> > Because of these am getting memory leak in my code.
>
> How can you tell? On what platform? Using what SSL library? Using what
> libcurl
> version? Are you sure the leak isn't simply in your application code?
>
> --
>
> / daniel.haxx.se
>
>
> ------------------------------
>
> Message: 6
> Date: Tue, 21 Oct 2008 08:18:33 -0400
> From: Mohun Biswas <m_biswas_at_mailinator.com>
> Subject: Re: Debug code introduced...
> To: curl-library_at_cool.haxx.se
> Message-ID: <gdkhap$6ct$1_at_ger.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Daniel Stenberg wrote:
> > On Mon, 20 Oct 2008, Yang Tse wrote:
> >
> >> Now the question is. Do I leave it in for debug-enabled builds or do I
> >> simply wipe it out?
> >
> > I think you can wipe them completely since the debug-code already does
> > something similar with the memdebug-system, and on linux at least of
> > those errors are trapped with valgrind.
>
> Also, some malloc implementations offer this natively. For instance on
> OS X you can set MallocScribble and MallocPreScribble. Of course you may
> not have access to OS X but if you do it's a good place to debug malloc
> problems. For all I know these features may have been inherited from *BSD.
>
> MB
>
>
>
> ------------------------------
>
> Message: 7
> Date: Tue, 21 Oct 2008 09:07:04 -0500
> From: "Ralph Mitchell" <ralphmitchell_at_gmail.com>
> Subject: Re: question regarding CURLOPT_WRITEFUNCTION &
> CURLOPT_WRITEDATA
> To: "libcurl development" <curl-library_at_cool.haxx.se>
> Message-ID:
> <997a524e0810210707h61f2ee9bm486296b13937556_at_mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> On Tue, Oct 21, 2008 at 6:22 AM, Jan <haihappn_at_gmail.com> wrote:
>
> >
> >
> > 2008/10/21 Nikolai Kondrashov <Nikolai.Kondrashov_at_oktetlabs.ru>
> >
> >
> >> Are you interpreting it as a zero-terminated string?
> >>
> >
> > Well, i think so, because the struct uses a char pointer to store the
> > content of the chunk. the solution would be to change the struct in a way
> so
> > that it accepts also binary data, but it dont exactly know how to do
> this..
> >
>
> What needs to be changed?? I've just extracted the getinmemory.c example
> from the curl-7.18.2 tarball, altered the url to pick up the "powered by
> apache" PNG file from my local server, and added these lines right before
> "chunk" struct is freed:
>
> FILE *p;
> p=fopen("/tmp/image.png", "w");
> fwrite(chunk.memory, sizeof (char), chunk.size, p);
> fclose(p);
>
> The md5sum of the new file, /tmp/image.png, exactly matches the original
> and
> it displays just fine. Seems to me like getinmemory.c does a fine job of
> grabbing a binary file.
>
> Ralph Mitchell
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://cool.haxx.se/pipermail/curl-library/attachments/20081021/3178d277/attachment.htm
> >
>
> ------------------------------
>
> Message: 8
> Date: Tue, 21 Oct 2008 11:16:13 -0700
> From: Emanuel Norrbin <emanuel.norrbin_at_jitterbit.com>
> Subject: Re: transfer closed with outstanding read data remaining with
> Expect: 100-continue
> To: curl-library_at_cool.haxx.se
> Message-ID: <48FE1C6D.4090009_at_jitterbit.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> >
> >
> > /> HTTP/1.1 100 Continue /
> > /> Content-Length: 0 /
> > /> /
> > /> then I send the data and get the following headers back: /
> >
> > I wonder if perhaps the funny Content-Length: after the 100 Continue
> > can cause
> > some problem.
> >
> > Did you try sending the POST with Expect: 100 continue disabled?
> Daniel,
>
> I did not try that. I have now and the result is a success! Here is the
> curl debug output with 100 Continue disabled (I also disabled transfer
> content encoding which by itself does not make any difference)
> -----
> CURL DEBUG HEADER_OUT: POST /services/Soap/c/9.0/4c1600D3000000018EC
> HTTP/1.1
> Host: na2-api.salesforce.com
> Accept: */*
> Content-Type: text/xml; charset="utf-8"
> SOAPAction: ""
> Content-Length: 1290
> CURL DEBUG DATA_OUT: <Output data removed>
> CURL DEBUG HEADER_IN: HTTP/1.1 200 OK
> CURL DEBUG HEADER_IN: Server:
> CURL DEBUG HEADER_IN: Content-Type: text/xml; charset=utf-8
> CURL DEBUG HEADER_IN: Transfer-Encoding: chunked
> CURL DEBUG HEADER_IN: Date: Tue, 21 Oct 2008 17:49:23 GMT
> CURL DEBUG HEADER_IN:
> CURL DEBUG DATA_IN: 3f75
> <Input data removed>
> 0
>
> CURL DEBUG TEXT: Connection #0 to host na2-api.salesforce.com left intact
> CURL DEBUG TEXT: Closing connection #0
> CURL DEBUG TEXT: SSLv3, TLS alert, Client hello (1):
> -----
>
> This time the server does not send that Content-Length: 0 header back
> and it all works as expected.
> For your reference, the conversation that fails looks like this (with
> content encoding also turned off):
> -----
> CURL DEBUG HEADER_OUT: POST /services/Soap/c/9.0/4c1600D3000000018EC
> HTTP/1.1
> Host: na2-api.salesforce.com
> Accept: */*
> Content-Type: text/xml; charset="utf-8"
> SOAPAction: ""
> Content-Length: 1290
> Expect: 100-continue
>
> CURL DEBUG HEADER_IN: HTTP/1.1 100 Continue
> CURL DEBUG HEADER_IN: Server:
> CURL DEBUG HEADER_IN: Content-Length: 0
> CURL DEBUG HEADER_IN: Date: Tue, 21 Oct 2008 17:47:40 GMT
> CURL DEBUG DATA_OUT: <Output data removed>
> CURL DEBUG HEADER_IN: HTTP/1.1 200 OK
> CURL DEBUG HEADER_IN: Server:
> CURL DEBUG HEADER_IN: Content-Type: text/xml; charset=utf-8
> CURL DEBUG HEADER_IN: Transfer-Encoding: chunked
> CURL DEBUG HEADER_IN: Date: Tue, 21 Oct 2008 17:47:41 GMT
> CURL DEBUG HEADER_IN:
> CURL DEBUG TEXT: transfer closed with outstanding read data remaining
> CURL DEBUG TEXT: Closing connection #0
> CURL DEBUG TEXT: SSLv3, TLS alert, Client hello (1):
> CURL DEBUG UNKNOWN:
> -----
>
> Could it be that curl is looking at that Content-Length set to 0 and
> then does not expect chunked transfer encoding of the input data?
>
> As it is now I have two solutions to the problem: Send
> "Transfer-Encoding: chunked" header or don't send "Expect: 100-continue"
> header. In both cases the server does not send the "Content-Length: 0"
> header back so you may be on to something.
>
> /Thanks
> Emanuel
>
>
>
>
> ------------------------------
>
> Message: 9
> Date: Tue, 21 Oct 2008 21:13:09 +0200
> From: Josef Wolf <jw_at_raven.inka.de>
> Subject: SSL and basic authentication.
> To: curl-library_at_cool.haxx.se
> Message-ID: <20081021191309.GB20766_at_raven.wolf.lan>
> Content-Type: text/plain; charset=us-ascii
>
> Hello,
>
> I am trying to understand how to correctly use curl with SSL and basic
> authentication.
>
> I started investigating because I tried to set up a git repository with
> SSL and basic authentication. It seems to me like git don't uses libcurl
> in a way as libcurl is meant to be used. But I am new to both, git _and_
> libcurl, so I am not sure whether my guess is correct.
>
> I have wrote more details about my setup in
>
> http://marc.info/?l=git&m=122426078301793&w=2
>
> But before I start asking questions about how git uses curl, I want to
> get some basic understanding, so I did some tests.
>
> First question is: what is the default place where curl searches for
> CA certificates? I have to explicitly use the --cacert or the --capath
> options if I want to use the certificates that come with openssl.
>
> As a workaround, I put this into ~/.curlrc:
>
> $ echo -- --capath /etc/ssl/certs > ~/.curlrc
>
> Now I try authentication:
>
> $ curl https://test.host/git/test1/HEAD
> [ 401 error ]
> $ curl https://user@test.host/git/test1/HEAD
> [ 401 error ]
> $ curl --user user https://test.host/git/test1/HEAD
> Enter host password for user 'user':
> [ works ]
>
> Curl asks me for a password and retrieves the file only if I supply
> the --user option.
>
> First problem is, prefixing user in front of hostname don't work.
> IMHO, this is a bug in curl, since this format is explicitly documented.
>
> Next problem is that curl don't ask credentials on a 401 error. Is
> this really the right thing to do? I always thought that on 401,
> the user-agent should present the realm, ask the user for credentials,
> and finally retry the request with the supplied credentials. At least,
> this is how I understand
>
> http://en.wikipedia.org/wiki/Basic_access_authentication#Example
>
> For example, libwww allows to install a callback to help the client
> find out which user/password combination to supply for a given
> URL/Realm combination.
>
> Next, I try to find out how to use libcurl so that it asks me for a
> password:
>
> $ curl --libcurl x.c --user user https://test.host/git/test1/HEAD>/dev/null
> Enter host password for user 'user':
>
> The resulting source file retrieves the URL without asking me for a
> password. When I remove the CURLOPT_USERPWD setting, the retrieval
> fails again.
>
> Opinions?
>
>
> ------------------------------
>
> _______________________________________________
> curl-library mailing list
> curl-library_at_cool.haxx.se
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-library
>
>
> End of curl-library Digest, Vol 38, Issue 45
> ********************************************
>

-- 
VIJAY
Received on 2008-10-22