Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"CURLE_OUT_OF_MEMORY" error when posting via https

I am attempting to write an application that uses libCurl to post soap requests to a secure web service. This Windows application is built against libCurl version 7.19.0 which, in turn, is built against openssl-0.9.8i. The pertinent curl related code follows:

FILE *input_file = fopen(current->post_file_name.c_str(), "rb");
FILE *output_file = fopen(current->results_file_name.c_str(), "wb");
if(input_file && output_file)
{
    struct curl_slist *header_opts = 0;
    CURLcode rcd;

    header_opts = curl_slist_append(header_opts, "Content-Type: application/soap+xml; charset=utf8");
    curl_easy_reset(curl_handle);
    curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
    curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, output_file);
    curl_easy_setopt(curl_handle, CURLOPT_READDATA, input_file);
    curl_easy_setopt(curl_handle, CURLOPT_URL, fs_service_url);
    curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
    curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, header_opts);
    rcd = curl_easy_perform(curl_handle);
    if(rcd != 0)
    {
        current->curl_result = rcd;
        current->curl_error = curl_easy_strerror(rcd);
    }
    curl_slist_free_all(header_opts);
}

When I attempt to execute the URL, curl returns an CURLE_OUT_OF_MEMORY error which appears to be related to a failure to allocate an SSL context. Has anyone else encountered this problem before?

like image 460
Jon Trauntvein Avatar asked Oct 03 '08 12:10

Jon Trauntvein


2 Answers

I had the same problem, just thought I'd add the note that rather than calling the OpenSsl export SSL_library_init directly it can be fixed by adding the flag CURL_GLOBAL_SSL to curl_global_init

like image 157
Glen Avatar answered Nov 12 '22 19:11

Glen


After further investigation, I found that this error was due to a failure to initialise the openSSL library by calling SSL_library_init().

like image 30
Jon Trauntvein Avatar answered Nov 12 '22 19:11

Jon Trauntvein