cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Really weird problem with CURLOPT_WRITEFUNCTION

From: Joshua McCracken <h.samantha529_at_gmail.com>
Date: Wed, 23 Dec 2009 08:50:18 -0500

*fixed the code I was using. I have no idea what I was trying to do passing
a void pointer to data that wasn't even null terminated to another function
for parsing using cstring functions without even casting it first lol. It's
still segfaulting though and I have isolated the location of the problem to
the dynamic memory allocation occurring at the same location. Maybe a
symptom of a problem elsewhere? Not sure. I'm dead tired - haven't slept in
over 24 hours. Going to get some rest and work on it some more when I wake
up. If anyone has any suggestions, they'd be much appreciated in the
meantime.

Updated code:

int get_url_data(void *buff, size_t size, size_t bytes, void *userp)
{
size_t actual_size = size * bytes;
struct writestruct *memory = (struct writestruct *)userp;
char *temp;

            memory->wdatas = malloc(memory->size + actual_size + 1);
            if (memory->wdatas)
            { //time to copy data from buffer to struct
                memcpy(&(memory->wdatas[memory->size]), buff, actual_size);
                memory->size += actual_size;
                memory->wdatas[memory->size] = 0;//null terminate
            }

            temp = strtok(datas.errstr, ", ");
            parse(memory->wdatas, temp);
            while (temp != NULL)
            {
                temp = strtok(NULL, ", ");
                parse(memory->wdatas, temp);
            }

            return actual_size;

}

Last part of strace output:

clock_gettime(CLOCK_MONOTONIC, {32737, 174925238}) = 0
mmap2(NULL, 3087618048, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = -1 ENOMEM (Cannot allocate memory)
mmap2(NULL, 3087749120, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = -1 ENOMEM (Cannot allocate memory)
mmap2(NULL, 2097152, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1,
0) = 0xb7855000
munmap(0xb7855000, 700416) = 0
munmap(0xb7a00000, 348160) = 0
mprotect(0xb7900000, 135168, PROT_READ|PROT_WRITE) = 0
mmap2(NULL, 3087618048, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = -1 ENOMEM (Cannot allocate memory)
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Process 7223 detached

GDB Output:
[New Thread 0xb7a406d0 (LWP 8911)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7a406d0 (LWP 8911)]
0xb7f48dc3 in strstr () from /lib/tls/i686/cmov/libc.so.6

-- 
Freelance Writer @ http://www.helium.com/users/456368
Owner @ http://logicdoctrine.blogspot.com

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-12-23