curl-library
Memory Access error
Date: Sun, 11 May 2003 18:26:04 -0600
We're writing code against a version of libcurl 7.10.3 we built for
windows (couldn't get 7.10.4 to build). Our ftp upload code is
running into a memory exception in the fread function on the
_lock_str(stream) call. I'm not sure what we're doing wrong. I'm
sure we're just doing something dumb, but I haven't been able to
find. Here is a few code snippets (hopefully someone can spot it):
CURL *curl;
CURLcode res;
FILE *fileToRead = NULL;
char curlErrBuffer[CURL_ERROR_SIZE] = {0};
/* get a curl handle */
curl = curl_easy_init();
if( !curl )
{
ERROR_MESSAGE(_T("FTP Web-Upload Error"), _T("Could not
initialize cURL.") );
return;
}
// setup the error buffer
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlErrBuffer) ;
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
// no signal in multi-threaded environment
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, TRUE) ;
/* specify target */
curl_easy_setopt(curl,CURLOPT_URL, strURL);
/* login/password */
curl_easy_setopt(curl, CURLOPT_USERPWD, strLoginPass);
int hd ;
struct stat file_info;
/* get the file size of the local file */
hd = _open(strCacheFile, _O_RDONLY) ;
fstat(hd, &file_info);
// open the file
fileToRead = _fdopen( hd, "r");
if( NULL != fileToRead )
{
/* now specify which file to upload */
curl_easy_setopt(curl, CURLOPT_INFILE, fileToRead);
/* and give the size of the upload (optional) */
curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_info.st_size);
// perform the upload
res = curl_easy_perform(curl);
if( 0 != res )
{
CAtlString strError;
strError.Format( _T("Failed to complete upload of
%s.\r\nError message: \"%S\"\r\nError number: %d"),
lpFindFileData->cFileName, curlErrBuffer, res );
ERROR_MESSAGE(_T("FTP Web-Upload Error"), strError );
}
fclose( fileToRead );
}
curl_easy_cleanup(curl);
Thanks for the help,
-- Jared McIntyre Deep Fried Software Deep Fried LLC Owner/Engineer http://www.dfsoftware.com jmcintyre_at_dfsoftware.com ------------------------------------------------------- Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara The only event dedicated to issues related to Linux enterprise solutions www.enterpriselinuxforum.comReceived on 2003-05-12