cURL / Mailing Lists / curl-library / Single Mail


Segmentation fault???

From: Wei Weng <>
Date: Mon, 24 Nov 2008 23:35:40 -0500

I am using the following code to test:

#include <stdio.h>

#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

#define LOCAL_FILE "/tmp/uploadthis.txt"
#define UPLOAD_FILE_AS "while-uploading.txt"
#define REMOTE_URL "ftp://user:pass@localhost/" UPLOAD_FILE_AS

int main(int argc, char **argv)
        CURL* curl;
        CURLcode res;
        FILE* err;
        FILE* hd_src;


        curl = curl_easy_init();
        if( curl )
                err = fopen("/tmp/stderr.log", "a");
                hd_src = fopen(LOCAL_FILE, "r");

                curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
                curl_easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
                curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
                curl_easy_setopt(curl, CURLOPT_URL, REMOTE_URL);
                curl_easy_setopt(curl, CURLOPT_STDERR, err);
                curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

                res = curl_easy_perform(curl);

                if( err )
                        err = NULL;

                if( hd_src )
                        hd_src = NULL;


                fprintf(stderr, "curl told us %d\n", res);


        return 0;

And it crashed.

I have the backtrace.

GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) run
Starting program: /home/wweng/test
[Thread debugging using libthread_db enabled]
[New Thread 0xb7a426b0 (LWP 25730)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7a426b0 (LWP 25730)]
0xb7e4f412 in free () from /lib/tls/i686/cmov/
(gdb) bt
#0 0xb7e4f412 in free () from /lib/tls/i686/cmov/
#1 0xb7e4b924 in _IO_free_backup_area () from /lib/tls/i686/cmov/
#2 0xb7e49732 in _IO_file_overflow () from /lib/tls/i686/cmov/
#3 0xb7e487a5 in _IO_file_xsputn () from /lib/tls/i686/cmov/
#4 0xb7e3e60a in fwrite () from /lib/tls/i686/cmov/
#5 0xb7f6a547 in showit (data=0x9654840, type=CURLINFO_HEADER_OUT,
ptr=0xbfbbf6ec "QUIT\r\n", size=6) at sendf.c:715
#6 0xb7f6a731 in Curl_debug (data=0x9654840, type=CURLINFO_HEADER_OUT,
ptr=0xbfbbf6ec "QUIT\r\n", size=6, conn=0x965d4a0) at sendf.c:762
#7 0xb7f70922 in Curl_nbftpsendf (conn=0x965d4a0, fmt=0xb7f9c72c "QUIT") at
#8 0xb7f70c2b in ftp_quit (conn=0x965d4a0) at ftp.c:3797
#9 0xb7f70c94 in ftp_disconnect (conn=0x965d4a0) at ftp.c:3826
#10 0xb7f74be6 in Curl_disconnect (conn=0x965d4a0) at url.c:2195
#11 0xb7f7547f in ConnectionKillOne (data=0x9654840) at url.c:2574
#12 0xb7f7186b in close_connections (data=0x9654840) at url.c:249
#13 0xb7f71b74 in Curl_close (data=0x9654840) at url.c:416
#14 0xb7f89dc8 in curl_easy_cleanup (curl=0x9654840) at easy.c:552
#15 0x080488e6 in main ()

And I used an slightly older CVS code for curl. It was 7.19.1. This code
crashed even on old 7.15 curl.

Am I doing something wrong??

Received on 2008-11-25