c++ - 在单音模式内调用 PQfinish 时出现分段错误
问题描述
我正在创建单调类,并想在 PGconn 对象中添加。
过去,此类将提供与 DB 的连接。
// postgresql
#include <libpq-fe.h>
//==============================================================================
class TestST
{
public:
static TestST& getInstance()
{
static TestST test;
return test;
}
bool createConnection()
{
mConn.reset( PQsetdbLogin("localhost", "5432", NULL, NULL,
"test_db", "user_app",
"passwd"),
&PQfinish); // [SIGSEGV when delete] passing a reference to the destroy function
return true;
}
private:
TestST()
{
}
private:
std::shared_ptr<PGconn> mConn; // smart pointer to postgres connetion object
};
//==============================================================================
int main(int argc, char** argv)
{
TestST::getInstance().createConnection(); // create singletone and connection
return 0;
}
//==============================================================================
当单音被删除时,函数 PQfinish 调用信号 Segmentation fault。如果我将 mConn 的初始化移动到构造函数 - 它的工作。如果我在 Windows (MSVC) 上构建和运行 - 它可以工作。
postgres 9.6.9 版;操作系统 - Debian 9;gcc 版本 6.3.0
解决方案
推荐阅读
- reactjs - 如何在 React Native 中创建全局布局组件?
- java - CompletableFuture 简化自定义示例
- url - 如何使用完全限定的服务器名称地址访问 Rabbitmq 管理 UI?
- python - Python 日期格式
- quaternions - 妙手镯;如何从四元数到前臂方向单位向量?
- nginx - Unirest 连接超时
- postgresql - 我在批量创建操作期间遇到了以下死锁。调试此问题的可能方法是什么?
- c# - 如何将对象列表转换为一维数组?
- android - 为什么 QBDialog 的收件人 ID 始终为空,但在 Quickblox 中有 2 个不同的对手 ID
- c++ - 使用 SFINAE 的 C++ 构造函数特化