I have following run time error sometimes (not all the times)
malloc: * error for object 0x14: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug
else
EXE_BAD_ACCESS
on the same line of code.
Please help me to solve this trouble.
I have following structure for curl based server connector. in curlBasedServerConnector.cpp see the place where >>>ERROR POINTED HERE line appear.
curlBasedServerConnector.hpp
class curlBasedServerConnector : public webServiceConnectorInterfaceA
{
private:
CURLcode curlCode;
CURL* curlHandle;
char* messagePtr;
std::string message = "";
static std::atomic<int> totalNumOfCurlProcesses;
static std::atomic<bool> isGlobalInitCalledAlready;
static std::mutex curlGlobalInitKey;
static size_t writeContents_s(char *buf, size_t size, size_t nmemb, void *up)
{
curlBasedServerConnector* pThis = static_cast<curlBasedServerConnector*>(up);
return pThis->writeContents(buf, size, nmemb);
}
// member version
size_t writeContents(char* buf, size_t size, size_t nmemb)
{
std::copy(buf, buf+(size*nmemb), std::back_inserter(message));
return size*nmemb;
}
public:
bool executeOperation()override ;
bool openConnection() override;
bool setHttpHeader(const char* contentType, const char* charSet)override;
bool setServerUrl(const char* url)override;
void setRequest(const char* request)override;
void closeConnection() override;
std::string getResponseAsString()override;
bool listenToNotification()override;
void setTrace(bool trace);
int getNumberofCurlProcessesInitialized();
curlBasedServerConnector()
{
curlGlobalInitKey.lock();
{
if(!isGlobalInitCalledAlready)
{
curlCode = curl_global_init(CURL_GLOBAL_ALL);
cout<<" Server Connector GLOBAL_INIT CALLED "<<endl;
isGlobalInitCalledAlready = true;
totalNumOfCurlProcesses++;
}
else
{
totalNumOfCurlProcesses++;
}
}
curlGlobalInitKey.unlock();
openConnection();
}
virtual ~curlBasedServerConnector(){
curlGlobalInitKey.lock();
totalNumOfCurlProcesses--;
if(totalNumOfCurlProcesses == 0)
{
curl_global_cleanup();
}
curlGlobalInitKey.unlock();
}
};
curlBasedServerConnector.cpp
bool curlBasedServerConnector::openConnection(){
bool successStatus = false;
if(curlHandle )
{
cout<<"curl hanlde --"<<curlHandle<<endl;
successStatus = true;
}
else
{
curlHandle = curl_easy_init();
if(curlHandle != NULL){
successStatus = true;
}
}
cout<<"openConnection() CURL CODE "<<curlCode<<endl;
return successStatus;
}
void curlBasedServerConnector::closeConnection(){
curl_easy_cleanup(curlHandle);
}
bool curlBasedServerConnector::setServerUrl(const char *url){
cout<<"curl handle at setting url "<<curlHandle<<endl;
curlCode = curl_easy_setopt(curlHandle, CURLOPT_URL, url); >>>ERROR POINTED HERE
bool successStatus = false;
if(curlCode == 0 | curlCode == CURLE_OK)
{
successStatus = true;
}
else if (curlCode == 27 | curlCode == CURLE_OUT_OF_MEMORY){
exit(8);
}
return successStatus;
}
webServiceConnectorInterfaceA.hpp
class webServiceConnectorInterfaceA
{
public:
virtual bool openConnection() = 0;
virtual bool executeOperation()= 0; //
virtual bool setHttpHeader(const char* contentType, const char* charSet) = 0;
virtual bool setServerUrl(const char* url)=0;
virtual void setRequest(const char* request)=0;
virtual void closeConnection() = 0;
virtual bool listenToNotification() = 0;
virtual std::string getResponseAsString()=0;
webServiceConnectorInterfaceA(){ };
~webServiceConnectorInterfaceA(){ };
};
I have accessor class which compose this class as following
class webServiceAccessor{
private:
const char* serverAddress = "http://localhost:2000";
std::shared_ptr<sharedQueue> gmsListenerQueue;
std::shared_ptr<webServiceConnectorInterfaceA> webServiceConnectorInterface;
webServiceAccessor(){}
~webServiceAccessor(){}
}
Why it throws such error on the same line ? Who cause this error curlBasedServerConnector class or class webServiceAccessor ? How to solve this or debug this? I am using C++11 in Xcode IDE. Thanks
Aucun commentaire:
Enregistrer un commentaire