J Curl via curl-library
2021-04-05 19:06:35 UTC
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
<https://curl.se/libcurl/c/anyauthput.html>and getinmemory.c
<https://curl.se/libcurl/c/getinmemory.html>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.
<https://drive.google.com/file/d/11YVmqj4qGxSy5Ax_55PYz6POzoYDGpyT/view?usp=sharing>
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
different.
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.
response in memory. To try this I have combined the anyauthput.c
<https://curl.se/libcurl/c/anyauthput.html>and getinmemory.c
<https://curl.se/libcurl/c/getinmemory.html>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.
<https://drive.google.com/file/d/11YVmqj4qGxSy5Ax_55PYz6POzoYDGpyT/view?usp=sharing>
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
different.
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.