| |
|
|
|
cURL Mailing List Monthly Index Single Mail
curl-library Mailing List Archives
Fwd: libcurl hangs in malloc_consolidate
From: Mark Wattier <mark.wattier_at_gmail.com>
Date: Fri, 23 Mar 2007 08:46:42 -0700
It was suggested I take this to curl-library instead of curl-users.
---------- Forwarded message ----------
We have a set of wrappers for curl that we have been using in our
We are using curl 7.15.5, and openssl-0.9.7m. This is on Red Hat
Any suggestions would be appreciated.
Core dump:
(gdb) where
Relevant code snippets:
static CURL *curl = NULL;
static struct MemoryStruct chunk;
struct MemoryStruct {
char *memory;
size_t size;
};
static size_t WriteMemoryCallback(void *ptr, size_t size, size_t
{
register int realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *) data;
mem->memory = (char *) realloc(mem->memory, mem->size + realsize + 1);
if (mem->memory) {
memcpy(&(mem->memory[mem->size]), ptr, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
}
return realsize;
}
int myapp_http_post2(char *url, char *postdata, char **result, int *len)
{
CURLcode res;
int rc;
MYAPP_DEBUG(0, "%s: entry", FN);
/******************************************************************************
**
** INITIALIZATION
**
\*****************************************************************************/
MYAPP_DEBUG(0, "%s: init", FN);
chunk.memory = NULL; /* we expect realloc(NULL, size) to work */
chunk.size = 0; /* no data at this point */
*len = 0;
if (!curl) {
MYAPP_DEBUG(0, "%s: curl_global_init", FN);
if ((res = curl_global_init(CURL_GLOBAL_DEFAULT)) != CURLE_OK) {
http_curl_error(FN, "curl_easy_init", "CURL_GLOBAL_DEFAULT", res);
return MYAPP_RC_INT_ERR;
}
MYAPP_DEBUG(0, "%s: curl_easy_init", FN);
if ((curl = curl_easy_init()) == NULL) {
http_curl_error(FN, "curl_easy_init", "", res);
return MYAPP_RC_INT_ERR;
}
MYAPP_DEBUG(0, "%s: myapp_http_set_params", FN);
if ((rc = myapp_http_set_params(curl)) != MYAPP_RC_INT_OK) {
return MYAPP_RC_INT_ERR;
}
/******************************************************************************
**
** CALLBACK FUNCTION
**
\*****************************************************************************/
/* send all data to this function */
MYAPP_DEBUG(0, "%s: curl_easy_setopt", FN);
if ((res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
http_curl_error(FN, "curl_easy_setopt",
return MYAPP_RC_INT_ERR;
}
/* we pass our 'chunk' struct to the callback function */
MYAPP_DEBUG(0, "%s: curl_easy_setopt", FN);
if ((res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)
http_curl_error(FN, "curl_easy_setopt", "CURLOPT_WRITEDATA", res);
return MYAPP_RC_INT_ERR;
}
}
/******************************************************************************
**
** URL
**
\*****************************************************************************/
MYAPP_DEBUG(0, "%s: curl_easy_setopt", FN);
if ((res = curl_easy_setopt(curl, CURLOPT_URL, url)) != CURLE_OK) {
http_curl_error(FN, "curl_easy_setopt", "CURLOPT_URL", res);
return MYAPP_RC_INT_ERR;
}
/******************************************************************************
**
** POSTDATA
**
\*****************************************************************************/
if ((postdata != NULL) && (postdata[0] != '\0')) {
MYAPP_DEBUG(0, "%s: curl_easy_setopt", FN);
if ((res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
http_curl_error(FN, "curl_easy_setopt", "CURLOPT_POSTFIELDS", res);
return MYAPP_RC_INT_ERR;
}
}
/******************************************************************************
**
** FETCH
**
\*****************************************************************************/
MYAPP_DEBUG(0, "%s: curl_easy_perform", FN);
if ((res = curl_easy_perform(curl)) != CURLE_OK) {
http_curl_error(FN, "curl_easy_perform", "curl", res);
switch (res) {
case CURLE_OPERATION_TIMEDOUT:
return MYAPP_RC_INT_TIMEOUT;
default:
return MYAPP_RC_INT_ERR;
}
}
MYAPP_DEBUG(0, "%s: curl_easy_perform returned OK", FN);
/* result is in chunk.memory, size of chunk.size. don't count on
*result = malloc(chunk.size + 1);
if (*result == NULL) {
MYAPP_PANIC(0, "%s: malloc error", FN);
/* NOTREACHED */
exit(0);
}
MYAPP_DEBUG(0, "%s: malloc OK", FN);
MYAPP_DEBUG(0, "%s: chunk:%s", FN,chunk.memory);
memcpy(*result, chunk.memory, chunk.size);
MYAPP_DEBUG(0, "%s: memcpy OK", FN);
(*result)[chunk.size] = 0;
*len = chunk.size;
MYAPP_DEBUG(0, "%s: result:%s", FN,*result);
/******************************************************************************
**
** REPORTING
**
\*****************************************************************************/
myapp_http_report(curl, url, myapp_http_post_result);
/******************************************************************************
**
** CLEANUP
**
\*****************************************************************************/
/* NOTE – in this test, persist is turned on so we keep the curl handle */
if (!HTTP_PROTOCOL_PERSIST) {
curl_easy_cleanup(curl);
curl_global_cleanup();
curl = NULL;
}
return MYAPP_RC_INT_OK;
}
These mail archives are generated by hypermail. |
Page updated November 12, 2010.
web site info