cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: out of memory error while posting form data

From: deva seetharam <tagsense_at_yahoo.com>
Date: Tue, 29 Jul 2008 20:21:08 -0700 (PDT)

here is the code (with the error checking removed, for brevity). it is arelatively simple code that posts a form with 3 text fields and 1 data file.

2 global variables:
static CURL* curlHandle;
static char curlUploadResult[4];

initialization function:
void initializeCurl() {
    CURLcode result;
    char msg[MAX_SYSLOG_MESSAGE_SIZE];

    result = curl_global_init(CURL_GLOBAL_ALL);
    curlHandle = curl_easy_init();
    result = curl_easy_setopt(curlHandle, CURLOPT_URL,DATAFILE_TARGET_URL);

    /* Disable SSL certificate verification, because our certificate
       doesn't verify */
    result = curl_easy_setopt(curlHandle, CURLOPT_SSL_VERIFYPEER, 0);
    result = curl_easy_setopt(curlHandle, CURLOPT_SSL_VERIFYHOST, 0);
        
        /* Set the callback function to get the server response data */
    result = curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, curlWriteCallback);

    result = curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, curlUploadResult);

    result = curl_easy_setopt(curlHandle, CURLOPT_VERBOSE, 1);
}

uploading function that gets called repeatedly:

int curlUploadData(char* data, unsigned int dataSize) {

    struct curl_httppost *post = NULL;
    struct curl_httppost *last = NULL;
    CURLcode result;
    char msg[MAX_SYSLOG_MESSAGE_SIZE];

        /* Add the username+password fields as multipart form data */
    curl_formadd(&post, &last,
        CURLFORM_COPYNAME, "username",
        CURLFORM_PTRCONTENTS, DATAFILE_TARGET_USERNAME,
        CURLFORM_END);

    curl_formadd(&post, &last,
        CURLFORM_COPYNAME, "password",
        CURLFORM_PTRCONTENTS, DATAFILE_TARGET_PASSWORD,
        CURLFORM_END);

    curl_formadd(&post, &last,
        CURLFORM_COPYNAME, "zone",
        CURLFORM_PTRCONTENTS, RADIO_ZONE,
        CURLFORM_END);

    /* Add the transmit buffer as a file upload as multipart form data,
       with form item name "datafile" */
    curl_formadd(&post, &last,
        CURLFORM_COPYNAME, "datafile",
        CURLFORM_BUFFER, "filename",
        CURLFORM_BUFFERPTR, data,
        CURLFORM_BUFFERLENGTH, dataSize,
        CURLFORM_END);

    /* Attach the form data to this request */
    result = curl_easy_setopt(curlHandle, CURLOPT_HTTPPOST, post);

    if (result) goto CLEAN_EXIT;
    
    result = curl_easy_perform(curlHandle);
    if (result) goto CLEAN_EXIT;

    snprintf(msg, MAX_SYSLOG_MESSAGE_SIZE,
        "File upload result code is %s",curlUploadResult);
    syslog(LOG_INFO, msg);

 CLEAN_EXIT:

    //cleanup code
    return SUCCESS;
}

callback function:
size_t curlWriteCallback(void *ptr, size_t size, size_t nmemb, void *stream) {

    if ((size*nmemb) > 0) {
        strncpy((char*) stream, (char*) ptr, 4);
    }

    return (size*nmemb);
}

thank you,
dave

--- On Tue, 7/29/08, Daniel Stenberg <daniel_at_haxx.se> wrote:

> From: Daniel Stenberg <daniel_at_haxx.se>
> Subject: Re: out of memory error while posting form data
> To: "libcurl development" <curl-library_at_cool.haxx.se>
> Date: Tuesday, July 29, 2008, 5:25 PM
> On Mon, 28 Jul 2008, deva seetharam wrote:
>
> > * SSL certificate verify result: self signed
> certificate (18), continuing anyway.
> > * failed creating formpost data
> > * Connection #0 to host [host name] left intact
> > * Out of memory
>
> Does it work on a 32bit debian?
>
> I've not seen this before. Can you provide an example
> source code that repeats
> it?
>
> --
>
> / daniel.haxx.se

      
Received on 2008-07-30