curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

CURLOPT_WRITEDATA user pointer not being passed in callback

From: J Curl via curl-library <>
Date: Mon, 5 Apr 2021 15:06:35 -0400

I am trying to write a http client to send a HTTPs PUT request and save the
response in memory. To try this I have combined the anyauthput.c
<>and getinmemory.c
<>examples but when I run it the
user pointer set via the CURLOPT_WRITEDATA is not being passed back in the
callback. Instead a different pointer is passed (and so trying to access it
leads to a segmentation fault).

I have put the code on my google drive if anyone cares to have a look.

I have reviewed the code many times and cannot see what it is I'm doing
wrong. I'm starting to suspect a bug in libcurl but would like to eliminate
anything obvious someone could see that I'm overlooking.

I print the value of the pointer set in CURLOPT_WRITEDATA and the value
that is passed when the callback is invoked and I can clearly see it is

in the main initialization:
struct MemoryStruct chunk;
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)(*&chunk*));
*printf("chunk: %p, chunk.memory: %p, chunk.size: %lu\n", &chunk,
chunk.memory, (unsigned long)chunk.size);*

in WriteMemoryCallback:
static size_t WriteMemoryCallback(void *contents, size_t size, size_t
nmemb, *void *userp*) {
  *fprintf(stderr, "contents: %p, size: %lu, nmemb: %lu, userp: %p\n",
contents, size, nmemb, userp);*

The print output shows the following:
chunk: *0x7ffc7f6ea470*, chunk.memory: 0x15b4840, chunk.size: 0
contents: 0x15d5dc0, size: 1, nmemb: 15, userp: *0x1593010*

Can anyone help ? Thanks.

Received on 2021-04-05