cURL / Mailing Lists / curl-library / Single Mail


Crash using WRITEDATA callback depending on CUSTOMREQUEST sent!

From: Arnaud Maye <>
Date: Wed, 14 Mar 2007 15:35:19 +0200

Hello, am having a crash problem when I use call back.

Details of my configuration:

-libcurl 7.16.1 (/MT - Multithread - .dll ) ( Release and debug builds )
-openssl-0.9.8e (/MT - Multithread - .lib) (Release and debug builds )
-Client ( /MT - Multithread )
-Visual Studio 2005 ( VC 8.0 )

Am trying to retrieve complete dirlist of a folder, in a ftp server
using SSL.
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "LIST -aL") ;

Each time I enable my call back WRITEDATA ( curl_easy_setopt(curl,
the application crash while calling curl_easy_perform(curl);

If I comment the _setopt function configuring the call back, it doesnt
crash anymore

More suprising is if I leave the call back enabled and I use "NST"
insteal "LIST -aL" it doesnt crash...
In the other hand, if I use "LIST" instead of "LIST -aL" application
keep crashing with the callback and not
crashing without the callback.

By crash I mean some crash in _perform without to even reach the callback

Here is my code :

#define REMOTE_URL ""

void ShellUpdater::GetDirName(void)
    CURL *curl;
    CURLcode res;

    memset(gData, 0, 600);

    /* In windows, this will init the winsock stuff */

    /* get a curl handle */
    curl = curl_easy_init();
    if(curl) {

        curl_easy_setopt(curl, CURLOPT_FTP_USE_EPSV, 0);
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
        curl_easy_setopt(curl, CURLOPT_FTP_SSL, 1);
        curl_easy_setopt(curl, CURLOPT_USERPWD, "cens:ored");
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);

        /* Allocate, zero ( get rid of terminator requirement and set
custom request*/
        char *CmdBuf = (char *)malloc(200);
        memset(CmdBuf, 0, 200);
        sprintf(CmdBuf, "LIST -aL");
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, CmdBuf) ;

        /* specify target */
        curl_easy_setopt(curl,CURLOPT_URL, REMOTE_URL);

        /* Set a client name, friendly */

        /* Declare my call back */
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteData);
        /* perform task */
        res = curl_easy_perform(curl);

        /* cleanup */

        /*free our custom command buffer */



size_t ShellUpdater::WriteData(void *buffer, size_t size, size_t nmemb,
void *userp)
    char *data = (char *)buffer;

    strcat_s(gData, 600, data);
    return size * nmemb;

As stated in the documentation, my callback is of course declared as a
static class member:

static size_t WriteData(void *buffer, size_t size, size_t nmemb, void

Details about the crash:

When running in debug mode I get a nag box : "Microsoft Visual Studio
C Runtime Library has detected a fatal error in shell.exe"

and the debugger point me here :

void __cdecl _CRT_DEBUGGER_HOOK(int _Reserved)
    /* assign 0 to _debugger_hook_dummy so that the function is not
folded in retail */
    _debugger_hook_dummy = 0;

In release mode, it is exactly same. Running the shell.exe outside of
Visual Studio, crash as well and ask me which debugger to use to debug.

Any ideas?

Warm regards
Received on 2007-03-14