Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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
Mongodb 如何对未初始化的bson_t变量执行bson_destroy()_Mongodb_Bson_Mongo C Driver - Fatal编程技术网

Mongodb 如何对未初始化的bson_t变量执行bson_destroy()

Mongodb 如何对未初始化的bson_t变量执行bson_destroy(),mongodb,bson,mongo-c-driver,Mongodb,Bson,Mongo C Driver,我有以下代码: bool ok; bson_t * query = bson_new(); BSON_APPEND_BINARY(query, "_id", BSON_SUBTYPE_BINARY, client_id, CLIENT_ID_SIZE); bson_t * update = bson_new(); bson_t update_ch1; BSON_APPEND_DOCUMENT_BEGIN(update, "$set", &update_ch1); BSON_

我有以下代码:

bool ok;

bson_t * query = bson_new();
BSON_APPEND_BINARY(query, "_id", BSON_SUBTYPE_BINARY, client_id, CLIENT_ID_SIZE);

bson_t * update = bson_new();
bson_t update_ch1;

BSON_APPEND_DOCUMENT_BEGIN(update, "$set", &update_ch1);
    BSON_APPEND_UTF8(&update_ch1, "est", "something");
bson_append_document_end(update, &update_ch1);

bson_t * fields = bson_new();

bson_t reply;
bson_error_t error;

ok = mongoc_collection_find_and_modify(
    client_collection,
    query,
    NULL,
    update,
    fields,
    false, // remove
    false, // upsert
    false, // new
    &reply,
    &error
);

if (!ok)
{
    fprintf(stderr, "Failed to update client collection in database: %s\n", error.message);
}

bson_destroy(fields);
bson_destroy(update);
bson_destroy(query);
bson_destroy(&reply); <---- Core dump here

可能使用BSON_初始值设定项?在我看来像是一个C驱动程序错误。无论发生什么情况,“回复”都应初始化。如果您没有使用最新的C驱动程序(1.6.3),请升级。如果您使用的是最新版本,请在CDRIVER项目中的jira.mongodb.org上打开一个票证好吗?但是,再次查看您的代码,我相信行
BSON\u APPEND\u BINARY(查询,“\u id”,BSON\u SUBTYPE\u BINARY,客户端\u id,“key”)不正确。它可能会导致内存损坏,从而导致崩溃。请更新您的问题,以显示什么是“client_id”以及它是如何初始化的?确实使用了旧版本的C驱动程序。我们将其替换为新的更新版本,并为任何静态BSON_t变量引入了BSON_初始值设定项宏。问题消失了。@A.JesseJiryuDavis-BSON\u APPEND\u二进制行中有一个错误。。。最后一个参数当然是长度。
 if (initilized(&reply)) bson_destroy(&reply);