Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 正在释放的curl\u easy\u opt throws EXE\u BAD\u访问或malloc指针未分配错误_C++_C++11_Pointers_Curl_Memory Leaks - Fatal编程技术网

C++ 正在释放的curl\u easy\u opt throws EXE\u BAD\u访问或malloc指针未分配错误

C++ 正在释放的curl\u easy\u opt throws EXE\u BAD\u访问或malloc指针未分配错误,c++,c++11,pointers,curl,memory-leaks,C++,C++11,Pointers,Curl,Memory Leaks,我有时(并非所有时候)出现以下运行时错误 malloc:*对象0x14的错误:未分配要释放的指针 *在malloc\u error\u break中设置断点以进行调试 否则 EXE\U坏访问(EXC\U I386\U GPFLT) 在同一行代码上 请帮我解决这个问题 对于基于curl的服务器连接器,我有以下结构。 在curlBasedServerConnector.cpp中,查看此处出现>>错误的位置 curlBasedServerConnector.hpp class curlBasedSe

我有时(并非所有时候)出现以下运行时错误

malloc:*对象0x14的错误:未分配要释放的指针 *在malloc\u error\u break中设置断点以进行调试

否则

EXE\U坏访问(EXC\U I386\U GPFLT)

在同一行代码上

请帮我解决这个问题

对于基于curl的服务器连接器,我有以下结构。 在curlBasedServerConnector.cpp中,查看此处出现>>错误的位置

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();      
    }  

};
我有一个访问器类,它组成了这个类,如下所示

class webServiceAccessor{
private:       
    const char* serverAddress = "http://localhost:2000";        
    std::shared_ptr<sharedQueue> gmsListenerQueue;
    std::shared_ptr<webServiceConnectorInterfaceA> webServiceConnectorInterface;

webServiceAccessor(){}
~webServiceAccessor(){} 

curlHandle
似乎未初始化。据我所知,您正在将随机垃圾传递给
curl\u easy\u setopt
。谢谢,我已经解决了这个问题。并更改为curlHandle=NULL;它似乎工作得很好。由于错误出现在随机的时间点,我有点怀疑我的初始化。将curlHandle初始化为NULL是否有效?这是有效的,因为它使
openConnection
实际调用
curl\u easy\u init()
。我打赌它以前没有这样做。对不起,我知道它在初始化为NULL之前起作用了。它只打开和关闭运行时错误。
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(){   };

};
class webServiceAccessor{
private:       
    const char* serverAddress = "http://localhost:2000";        
    std::shared_ptr<sharedQueue> gmsListenerQueue;
    std::shared_ptr<webServiceConnectorInterfaceA> webServiceConnectorInterface;

webServiceAccessor(){}
~webServiceAccessor(){} 
 GuardMalloc[TIFAR2-5307]: Allocations will be placed on 16 byte boundaries.
GuardMalloc[TIFAR2-5307]:  - Some buffer overruns may not be noticed.
GuardMalloc[TIFAR2-5307]:  - Applications using vector instructions (e.g., SSE) should work.
GuardMalloc[TIFAR2-5307]: version 108
TIFAR2(5307,0x100c31000) malloc: protecting edges
TIFAR2(5307,0x100c31000) malloc: stack logs being written into /tmp/stack-logs.5307.102c4c000.TIFAR2.M7TEpU.index
TIFAR2(5307,0x100c31000) malloc: recording malloc and VM allocation stacks to disk using standard recorder
TIFAR2(5307,0x100c31000) malloc: enabling scribbling to detect mods to free blocks
TIFAR2(5307,0x100c31000) malloc: process 5239 no longer exists, stack logs deleted from /tmp/stack-logs.5239.102c4c000.TIFAR2.YFARFr.index
WEB SERVICE CONNECTION STARTS HERE ......
 webServiceConnectorInterfaceA constructtor called 
.
.
.