cURL / Mailing Lists / curl-library / Single Mail


curl crash in setsockopt callback

From: Priyanka Shah <>
Date: Fri, 11 Apr 2014 17:07:02 -0700

I originally sent this to curl-users@, but this might be a more appropriate
place, hence re-posting.

I need to set a particular socket option through libcurl. I register a
sockopt callback, and set the socket option when callack is called. When I
ran this code, curl crashed with the following trace:
#0  0xf4586435 in sockopt_callback(void*, int, curlsocktype) ()
#1  0xf41f1011 in singleipconnect () from /usr/lib/
#2  0xf41f1b04 in Curl_connecthost () from /usr/lib/
#3  0xf41e0aa6 in Curl_setup_conn () from /usr/lib/
#4  0xf41e0ca6 in Curl_connect () from /usr/lib/
#5  0xf41ecd11 in Curl_do_perform () from /usr/lib/
#6  0xf41eda43 in curl_easy_perform () from /usr/lib/
Here's my code to register for sockopt callback.
            curl_easy_setopt(client, CURLOPT_SOCKOPTDATA, uint32_t data);
            curl_easy_setopt(client, CURLOPT_SOCKOPTFUNCTION,
And this is the callback's implementation:
    int sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype
        if(clientp == NULL) {
             return CURL_SOCKOPT_OK;
        uint32_t data = *(uint32_t*) clientp;
        sock_ctx lSockCtx;
        memset(&lSockCtx, 0, sizeof(lSockCtx)); = data;
        if (setsockopt(curlfd, SOL_IP, <opt-name>, &lSockCtx,
sizeof(lSockCtx)) < 0) {
            return CURL_SOCKOPT_ERROR;
        return CURL_SOCKOPT_OK;
I am not sure where to start debugging. Is there something here I am
missing? Any help would be appreciated.

List admin:
Received on 2014-04-12