Error in release version of cURL example

I apologise for asking another question. I was helped in getting cURL to work in this question: http://www.cplusplus.com/forum/windows/120990/

Again, I have Windows 7 64 bit Home Premium and Visual Studio 2010 Express.

I have made a (slight) amendment to the cURL example simple.c to replace fprint with cout and renamed it simple.cpp.

The project builds ok in debug and release, runs fine in debug but I get the following error when I try to run the release version:

First-chance exception at 0x770de3be in curlplus.exe: 0xC0000005: Access violation reading location 0x3ec0be26.
Unhandled exception at 0x770de3be in curlplus.exe: 0xC0000005: Access violation reading location 0x3ec0be26.

(I get the feeling at some time in Output I saw a warning, but did not see one just now when I built and ran everything.)

Here is the code:

#include <curl/curl.h>
#include <curl/easy.h>
#include<iostream>

using namespace std;

int main()
{
CURL *curl;//(nullptr);
CURLcode res;// = CURLE_OK;

// curl_global_init(CURL_GLOBAL_ALL);

curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

/* Perform the request, res will get the return code */
res = curl_easy_perform(curl); CODE CRASHES HERE - IF I INSERT BREAKPOINT ON NEXT LINE IT DOES NOT REACH IT
/* Check for errors */
if(res != CURLE_OK)
cout <<"curl_easy_perform() failed"; //curl_easy_strerror(res));

/* always cleanup */
curl_easy_cleanup(curl);
cin.get();
}
return 0;
}

At the point of error this file (dotdot.c) opens in Visual Studio with an arrow pointing to second to last line (I am not trying to shift the blame here, I am sure the error is due to my own inexperience!):

/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/

#include "curl_setup.h"

#include "dotdot.h"

#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"

/*
* "Remove Dot Segments"
* http://tools.ietf.org/html/rfc3986#section-5.2.4
*/

/*
* Curl_dedotdotify()
*
* This function gets a zero-terminated path with dot and dotdot sequences
* passed in and strips them off according to the rules in RFC 3986 section
* 5.2.4.
*
* The function handles a query part ('?' + stuff) appended but it expects
* that fragments ('#' + stuff) have already been cut off.
*
* RETURNS
*
* an allocated dedotdotified output string
*/
char *Curl_dedotdotify(char *input)
{
size_t inlen = strlen(input);
char *clone;
size_t clen = inlen; /* the length of the cloned input */
char *out = malloc(inlen+1);
char *outptr;
char *orgclone;
char *queryp;
if(!out)
return NULL; /* out of memory */

/* get a cloned copy of the input */
clone = strdup(input);
if(!clone) {
free(out);
return NULL;
}
orgclone = clone;
outptr = out;

/*
* To handle query-parts properly, we must find it and remove it during the
* dotdot-operation and then append it again at the end to the output
* string.
*/
queryp = strchr(clone, '?');
if(queryp)
*queryp = 0;

do {

/* A. If the input buffer begins with a prefix of "../" or "./", then
remove that prefix from the input buffer; otherwise, */

if(!strncmp("./", clone, 2)) {
clone+=2;
clen-=2;
}
else if(!strncmp("../", clone, 3)) {
clone+=3;
clen-=3;
}

/* B. if the input buffer begins with a prefix of "/./" or "/.", where
"." is a complete path segment, then replace that prefix with "/" in
the input buffer; otherwise, */
else if(!strncmp("/./", clone, 3)) {
clone+=2;
clen-=2;
}
else if(!strcmp("/.", clone)) {
clone[1]='/';
clone++;
clen-=1;
}

/* C. if the input buffer begins with a prefix of "/../" or "/..", where
".." is a complete path segment, then replace that prefix with "/" in
the input buffer and remove the last segment and its preceding "/" (if
any) from the output buffer; otherwise, */

else if(!strncmp("/../", clone, 4)) {
clone+=3;
clen-=3;
/* remove the last segment from the output buffer */
while(outptr > out) {
outptr--;
if(*outptr == '/')
break;
}
*outptr = 0; /* zero-terminate where it stops */
}
else if(!strcmp("/..", clone)) {
clone[2]='/';
clone+=2;
clen-=2;
/* remove the last segment from the output buffer */
while(outptr > out) {
outptr--;
if(*outptr == '/')
break;
}
*outptr = 0; /* zero-terminate where it stops */
}

/* D. if the input buffer consists only of "." or "..", then remove
that from the input buffer; otherwise, */

else if(!strcmp(".", clone) || !strcmp("..", clone)) {
*clone=0;
}

else {
/* E. move the first path segment in the input buffer to the end of
the output buffer, including the initial "/" character (if any) and
any subsequent characters up to, but not including, the next "/"
character or the end of the input buffer. */

do {
*outptr++ = *clone++;
clen--;
} while(*clone && (*clone != '/'));
*outptr = 0;
}

} while(*clone);

if(queryp) {
size_t qlen;
/* There was a query part, append that to the output. The 'clone' string
may now have been altered so we copy from the original input string
from the correct index. */
size_t oindex = queryp - orgclone;
qlen = strlen(&input[oindex]);
memcpy(outptr, &input[oindex], qlen+1); /* include the ending zero byte */
}

free(orgclone);ARROW POINTS HERE WHEN ERROR OCCURS
return out;
}

Locals window contains this info:

queryp 0x00000000 <Bad Ptr> char *
CXX0030: Error: expression cannot be evaluated

I am new to c++ so I am trying to give as much info as possible (without necessarily understanding the significance of what I give!). Here is call stack:

curlplus.exe!Curl_dedotdotify(char * input) Line 168 + 0xc bytes C
curlplus.exe!parseurlandfillconn(SessionHandle * data, connectdata * conn, bool * prot_missing, char * * userp, char * * passwdp, char * * optionsp) Line 3869 + 0x9 bytes C
curlplus.exe!create_conn(SessionHandle * data, connectdata * * in_connect, bool * async) Line 5130 + 0x1d bytes C
curlplus.exe!Curl_connect(SessionHandle * data, connectdata * * in_connect, bool * asyncp, bool * protocol_done) Line 5615 + 0x11 bytes C
curlplus.exe!multi_runsingle(Curl_multi * multi, timeval now, SessionHandle * data) Line 1025 + 0x18 bytes C
curlplus.exe!curl_multi_perform(void * multi_handle, int * running_handles) Line 1727 + 0x15 bytes C
curlplus.exe!easy_transfer(void * multi) Line 705 + 0x11 bytes C
curlplus.exe!easy_perform(SessionHandle * data, bool events) Line 784 + 0x18 bytes C
curlplus.exe!curl_easy_perform(void * easy) Line 803 + 0xb bytes C
curlplus.exe!main() Line 43 + 0x6 bytes C++
curlplus.exe!__tmainCRTStartup() Line 555 + 0x17 bytes C
kernel32.dll!75ed336a()
ntdll.dll!770e9f72()
ntdll.dll!770e9f45()

Many thanks for any assistance that may be offered!
I'm having the exact same issue in release mode, did you ever manage to solve this? Does anyone have any suggestions? Thanks!
hi, sorry I just found the email alerting me to your reply. I have not touched cURL since January. I am sure what I did was go back to the solution in VS 2010 where I built the source code and produced a Release version of the same (originally just had debug version), used the .lib file produced from that for the release version of my final project, and it worked. hope it helps and works for you
antunny
I also encountered this problem, and if i compile c-ares as static lib,the ares_init will crash too.
Topic archived. No new replies allowed.