diff --git a/arangod/Cluster/ClusterMethods.cpp b/arangod/Cluster/ClusterMethods.cpp index cfdd3d45b9..9f7ad65980 100644 --- a/arangod/Cluster/ClusterMethods.cpp +++ b/arangod/Cluster/ClusterMethods.cpp @@ -546,7 +546,7 @@ int createDocumentOnCoordinator ( return createDocumentOnCoordinator(dbname, collname, waitForSync, - json.get(), + json, headers, responseCode, resultHeaders, @@ -563,7 +563,7 @@ int createDocumentOnCoordinator ( string const& dbname, string const& collname, bool waitForSync, - TRI_json_t* json, + std::unique_ptr& json, std::map const& headers, triagens::rest::HttpResponse::HttpResponseCode& responseCode, std::map& resultHeaders, @@ -578,7 +578,6 @@ int createDocumentOnCoordinator ( = ci->getCollection(dbname, collname); if (collinfo->empty()) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; } @@ -592,14 +591,14 @@ int createDocumentOnCoordinator ( // cluster-wide unique number. Note that we only know the sharding // attributes a bit further down the line when we have determined // the responsible shard. - TRI_json_t* subjson = TRI_LookupObjectJson(json, TRI_VOC_ATTRIBUTE_KEY); + TRI_json_t* subjson = TRI_LookupObjectJson(json.get(), TRI_VOC_ATTRIBUTE_KEY); bool userSpecifiedKey = false; string _key; if (subjson == nullptr) { // The user did not specify a key, let's create one: uint64_t uid = ci->uniqid(); _key = triagens::basics::StringUtils::itoa(uid); - TRI_Insert3ObjectJson(TRI_UNKNOWN_MEM_ZONE, json, TRI_VOC_ATTRIBUTE_KEY, + TRI_Insert3ObjectJson(TRI_UNKNOWN_MEM_ZONE, json.get(), TRI_VOC_ATTRIBUTE_KEY, TRI_CreateStringReferenceJson(TRI_UNKNOWN_MEM_ZONE, _key.c_str(), _key.size())); } @@ -610,26 +609,22 @@ int createDocumentOnCoordinator ( // Now find the responsible shard: bool usesDefaultShardingAttributes; ShardID shardID; - int error = ci->getResponsibleShard( collid, json, true, shardID, + int error = ci->getResponsibleShard( collid, json.get(), true, shardID, usesDefaultShardingAttributes ); if (error == TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); return TRI_ERROR_CLUSTER_SHARD_GONE; } // Now perform the above mentioned check: if (userSpecifiedKey && ! usesDefaultShardingAttributes) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); return TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY; } if (userSpecifiedKey && ! collinfo->allowUserKeys()) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); return TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY; } - string const body = JsonHelper::toString(json); - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); + string const body = JsonHelper::toString(json.get()); // Send a synchronous request to that shard using ClusterComm: auto res = cc->syncRequest("", TRI_NewTickServer(), "shard:" + shardID, @@ -1370,7 +1365,7 @@ int modifyDocumentOnCoordinator ( std::unique_ptr json(triagens::basics::VelocyPackHelper::velocyPackToJson(slice)); return modifyDocumentOnCoordinator(dbname, collname, key, rev, policy, waitForSync, isPatch, keepNull, mergeObjects, - json.get(), headers, responseCode, resultHeaders, resultBody); + json, headers, responseCode, resultHeaders, resultBody); } //////////////////////////////////////////////////////////////////////////////// @@ -1387,7 +1382,7 @@ int modifyDocumentOnCoordinator ( bool isPatch, bool keepNull, // only counts for isPatch == true bool mergeObjects, // only counts for isPatch == true - TRI_json_t* json, + std::unique_ptr& json, std::unique_ptr>& headers, triagens::rest::HttpResponse::HttpResponseCode& responseCode, map& resultHeaders, @@ -1401,7 +1396,6 @@ int modifyDocumentOnCoordinator ( std::shared_ptr collinfo = ci->getCollection(dbname, collname); if (collinfo->empty()) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; } string collid = StringUtils::itoa(collinfo->id()); @@ -1432,13 +1426,12 @@ int modifyDocumentOnCoordinator ( ShardID shardID; int error = ci->getResponsibleShard(collid, - json, + json.get(), ! isPatch, shardID, usesDefaultShardingAttributes); if (error == TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); return error; } @@ -1470,8 +1463,7 @@ int modifyDocumentOnCoordinator ( } auto body = std::make_shared - (std::string(JsonHelper::toString(json))); - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); + (std::string(JsonHelper::toString(json.get()))); if (! isPatch || error != TRI_ERROR_CLUSTER_NOT_ALL_SHARDING_ATTRIBUTES_GIVEN) { @@ -1556,7 +1548,7 @@ int createEdgeOnCoordinator ( string const& dbname, string const& collname, bool waitForSync, - TRI_json_t* json, + std::unique_ptr& json, char const* from, char const* to, triagens::rest::HttpResponse::HttpResponseCode& responseCode, @@ -1571,7 +1563,6 @@ int createEdgeOnCoordinator ( std::shared_ptr collinfo = ci->getCollection(dbname, collname); if (collinfo->empty()) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; } string collid = StringUtils::itoa(collinfo->id()); @@ -1584,14 +1575,14 @@ int createEdgeOnCoordinator ( // cluster-wide unique number. Note that we only know the sharding // attributes a bit further down the line when we have determined // the responsible shard. - TRI_json_t* subjson = TRI_LookupObjectJson(json, "_key"); + TRI_json_t* subjson = TRI_LookupObjectJson(json.get(), "_key"); bool userSpecifiedKey = false; string _key; if (subjson == nullptr) { // The user did not specify a key, let's create one: uint64_t uid = ci->uniqid(); _key = triagens::basics::StringUtils::itoa(uid); - TRI_Insert3ObjectJson(TRI_UNKNOWN_MEM_ZONE, json, "_key", + TRI_Insert3ObjectJson(TRI_UNKNOWN_MEM_ZONE, json.get(), "_key", TRI_CreateStringReferenceJson(TRI_UNKNOWN_MEM_ZONE, _key.c_str(), _key.size())); } @@ -1602,21 +1593,18 @@ int createEdgeOnCoordinator ( // Now find the responsible shard: bool usesDefaultShardingAttributes; ShardID shardID; - int error = ci->getResponsibleShard( collid, json, true, shardID, + int error = ci->getResponsibleShard( collid, json.get(), true, shardID, usesDefaultShardingAttributes ); if (error == TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); return TRI_ERROR_CLUSTER_SHARD_GONE; } // Now perform the above mentioned check: if (userSpecifiedKey && !usesDefaultShardingAttributes) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); return TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY; } - string body = JsonHelper::toString(json); - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); + string body = JsonHelper::toString(json.get()); // Send a synchronous request to that shard using ClusterComm: map headers; diff --git a/arangod/Cluster/ClusterMethods.h b/arangod/Cluster/ClusterMethods.h index 8ca5993304..624cff7862 100644 --- a/arangod/Cluster/ClusterMethods.h +++ b/arangod/Cluster/ClusterMethods.h @@ -141,7 +141,7 @@ namespace triagens { std::string const& dbname, std::string const& collname, bool waitForSync, - TRI_json_t* json, + std::unique_ptr& json, std::map const& headers, triagens::rest::HttpResponse::HttpResponseCode& responseCode, std::map& resultHeaders, @@ -266,7 +266,7 @@ namespace triagens { bool isPatch, bool keepNull, // only counts for isPatch == true bool mergeObjects, // only counts for isPatch == true - TRI_json_t* json, + std::unique_ptr& json, std::unique_ptr>& headers, triagens::rest::HttpResponse::HttpResponseCode& responseCode, std::map& resultHeaders, @@ -280,7 +280,7 @@ namespace triagens { std::string const& dbname, std::string const& collname, bool waitForSync, - TRI_json_t* json, + std::unique_ptr& json, char const* from, char const* to, triagens::rest::HttpResponse::HttpResponseCode& responseCode, diff --git a/arangod/RestHandler/RestCursorHandler.cpp b/arangod/RestHandler/RestCursorHandler.cpp index a9280a3dd3..cb64be15d4 100644 --- a/arangod/RestHandler/RestCursorHandler.cpp +++ b/arangod/RestHandler/RestCursorHandler.cpp @@ -731,7 +731,8 @@ void RestCursorHandler::createCursor () { try { bool parseSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parseSuccess); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, parseSuccess); if (! parseSuccess) { return; diff --git a/arangod/RestHandler/RestDocumentHandler.cpp b/arangod/RestHandler/RestDocumentHandler.cpp index 8db4238db1..c4c4e0d34a 100644 --- a/arangod/RestHandler/RestDocumentHandler.cpp +++ b/arangod/RestHandler/RestDocumentHandler.cpp @@ -303,7 +303,9 @@ bool RestDocumentHandler::createDocument () { bool const waitForSync = extractWaitForSync(); bool parseSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parseSuccess); + VPackOptions options; + options.checkAttributeUniqueness = true; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, parseSuccess); if (! parseSuccess) { return false; } @@ -1397,7 +1399,8 @@ bool RestDocumentHandler::modifyDocument (bool isPatch) { string const& key = suffix[1]; bool parseSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parseSuccess); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, parseSuccess); if (! parseSuccess) { return false; } diff --git a/arangod/RestHandler/RestEdgeHandler.cpp b/arangod/RestHandler/RestEdgeHandler.cpp index 2b73e3ff62..958123ad10 100644 --- a/arangod/RestHandler/RestEdgeHandler.cpp +++ b/arangod/RestHandler/RestEdgeHandler.cpp @@ -203,7 +203,8 @@ bool RestEdgeHandler::createDocument () { bool const waitForSync = extractWaitForSync(); try { bool parseSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parseSuccess); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, parseSuccess); if (! parseSuccess) { return false; } @@ -345,11 +346,11 @@ bool RestEdgeHandler::createDocumentCoordinator (string const& collname, map resultHeaders; string resultBody; + std::unique_ptr json + (triagens::basics::VelocyPackHelper::velocyPackToJson(document)); int error = triagens::arango::createEdgeOnCoordinator( dbname, collname, waitForSync, - triagens::basics::VelocyPackHelper::velocyPackToJson(document), - from, to, - responseCode, resultHeaders, resultBody); + json, from, to, responseCode, resultHeaders, resultBody); if (error != TRI_ERROR_NO_ERROR) { generateTransactionError(collname.c_str(), error); diff --git a/arangod/RestHandler/RestEdgesHandler.cpp b/arangod/RestHandler/RestEdgesHandler.cpp index 0ff673a2b8..022f17b703 100644 --- a/arangod/RestHandler/RestEdgesHandler.cpp +++ b/arangod/RestHandler/RestEdgesHandler.cpp @@ -423,7 +423,8 @@ bool RestEdgesHandler::readEdgesForMultipleVertices () { } bool parseSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parseSuccess); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, parseSuccess); if (! parseSuccess) { // A body is required @@ -555,7 +556,8 @@ bool RestEdgesHandler::readEdgesForMultipleVertices () { bool RestEdgesHandler::readFilteredEdges () { std::vector expressions; bool parseSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parseSuccess); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, parseSuccess); if (! parseSuccess) { // We continue unfiltered // Filter could be done by caller diff --git a/arangod/RestHandler/RestExportHandler.cpp b/arangod/RestHandler/RestExportHandler.cpp index 636c6f1d89..6a7ec5bbf6 100644 --- a/arangod/RestHandler/RestExportHandler.cpp +++ b/arangod/RestHandler/RestExportHandler.cpp @@ -378,7 +378,8 @@ void RestExportHandler::createCursor () { try { bool parseSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parseSuccess); + VPackOptions vpoptions; + std::shared_ptr parsedBody = parseVelocyPackBody(&vpoptions, parseSuccess); if (! parseSuccess) { return; diff --git a/arangod/RestHandler/RestQueryCacheHandler.cpp b/arangod/RestHandler/RestQueryCacheHandler.cpp index 404d7ffe08..db76a3dfd8 100644 --- a/arangod/RestHandler/RestQueryCacheHandler.cpp +++ b/arangod/RestHandler/RestQueryCacheHandler.cpp @@ -225,7 +225,8 @@ bool RestQueryCacheHandler::replaceProperties () { return true; } bool validBody = true; - std::shared_ptr parsedBody = parseVelocyPackBody(validBody); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, validBody); if (! validBody) { // error message generated in parseJsonBody diff --git a/arangod/RestHandler/RestQueryHandler.cpp b/arangod/RestHandler/RestQueryHandler.cpp index d66477f3dc..9a1171e12a 100644 --- a/arangod/RestHandler/RestQueryHandler.cpp +++ b/arangod/RestHandler/RestQueryHandler.cpp @@ -504,7 +504,8 @@ bool RestQueryHandler::replaceProperties () { } bool parseSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parseSuccess); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, parseSuccess); if (! parseSuccess) { // error message generated in parseVelocyPackBody return true; @@ -645,7 +646,8 @@ bool RestQueryHandler::parseQuery () { } bool parseSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parseSuccess); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, parseSuccess); if (! parseSuccess) { // error message generated in parseVelocyPackBody return true; diff --git a/arangod/RestHandler/RestReplicationHandler.cpp b/arangod/RestHandler/RestReplicationHandler.cpp index f9d737b29c..9c35b4e547 100644 --- a/arangod/RestHandler/RestReplicationHandler.cpp +++ b/arangod/RestHandler/RestReplicationHandler.cpp @@ -1267,7 +1267,7 @@ void RestReplicationHandler::handleCommandLoggerFollow () { options.checkAttributeUniqueness = true; std::shared_ptr parsedRequest; try { - parsedRequest = _request->toVelocyPack(options); + parsedRequest = _request->toVelocyPack(&options); } catch (...) { generateError(HttpResponse::BAD, @@ -1855,7 +1855,7 @@ void RestReplicationHandler::handleCommandRestoreCollection () { options.checkAttributeUniqueness = true; try { - parsedRequest = _request->toVelocyPack(options); + parsedRequest = _request->toVelocyPack(&options); } catch (...) { generateError(HttpResponse::BAD, @@ -1927,7 +1927,7 @@ void RestReplicationHandler::handleCommandRestoreIndexes () { options.checkAttributeUniqueness = true; try { - parsedRequest = _request->toVelocyPack(options); + parsedRequest = _request->toVelocyPack(&options); } catch (...) { generateError(HttpResponse::BAD, @@ -2953,7 +2953,7 @@ void RestReplicationHandler::handleCommandRestoreDataCoordinator () { options.checkAttributeUniqueness = true; std::shared_ptr parsedAnswer; try { - parsedAnswer = result.answer->toVelocyPack(options); + parsedAnswer = result.answer->toVelocyPack(&options); } catch (VPackException const& e) { // Only log this error and try the next doc @@ -2983,7 +2983,7 @@ void RestReplicationHandler::handleCommandRestoreDataCoordinator () { options.checkAttributeUniqueness = true; std::shared_ptr parsedAnswer; try { - parsedAnswer = result.answer->toVelocyPack(options); + parsedAnswer = result.answer->toVelocyPack(&options); } catch (VPackException const& e) { // Only log this error and try the next doc @@ -3288,7 +3288,8 @@ void RestReplicationHandler::handleCommandFetchKeys () { } else { bool success; - std::shared_ptr parsedIds = parseVelocyPackBody(success); + VPackOptions options; + std::shared_ptr parsedIds = parseVelocyPackBody(&options, success); if (! success) { collectionKeys->release(); return; @@ -3875,7 +3876,8 @@ void RestReplicationHandler::handleCommandDump () { void RestReplicationHandler::handleCommandMakeSlave () { bool success; - std::shared_ptr parsedBody = parseVelocyPackBody(success); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, success); if (! success) { generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER); return; @@ -4106,7 +4108,8 @@ void RestReplicationHandler::handleCommandMakeSlave () { void RestReplicationHandler::handleCommandSync () { bool success; - std::shared_ptr parsedBody = parseVelocyPackBody(success); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, success); if (! success) { generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER); return; @@ -4573,7 +4576,8 @@ void RestReplicationHandler::handleCommandApplierSetConfig () { TRI_InitConfigurationReplicationApplier(&config); bool success; - std::shared_ptr parsedBody = parseVelocyPackBody(success); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, success); if (! success) { generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER); diff --git a/arangod/RestHandler/RestSimpleHandler.cpp b/arangod/RestHandler/RestSimpleHandler.cpp index b146890456..5f18a9b83e 100644 --- a/arangod/RestHandler/RestSimpleHandler.cpp +++ b/arangod/RestHandler/RestSimpleHandler.cpp @@ -79,7 +79,8 @@ HttpHandler::status_t RestSimpleHandler::execute () { if (type == HttpRequest::HTTP_REQUEST_PUT) { bool parsingSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parsingSuccess); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, parsingSuccess); if (! parsingSuccess) { return status_t(HANDLER_DONE); diff --git a/arangod/RestHandler/RestSimpleQueryHandler.cpp b/arangod/RestHandler/RestSimpleQueryHandler.cpp index dc89803595..7a703cd07b 100644 --- a/arangod/RestHandler/RestSimpleQueryHandler.cpp +++ b/arangod/RestHandler/RestSimpleQueryHandler.cpp @@ -174,7 +174,8 @@ HttpHandler::status_t RestSimpleQueryHandler::execute () { void RestSimpleQueryHandler::allDocuments () { try { bool parseSuccess = true; - std::shared_ptr parsedBody = parseVelocyPackBody(parseSuccess); + VPackOptions options; + std::shared_ptr parsedBody = parseVelocyPackBody(&options, parseSuccess); if (! parseSuccess) { return; diff --git a/arangod/RestHandler/RestVocbaseBaseHandler.cpp b/arangod/RestHandler/RestVocbaseBaseHandler.cpp index da3de38863..0d25dae3a8 100644 --- a/arangod/RestHandler/RestVocbaseBaseHandler.cpp +++ b/arangod/RestHandler/RestVocbaseBaseHandler.cpp @@ -574,10 +574,10 @@ bool RestVocbaseBaseHandler::extractWaitForSync () const { /// @brief parses the body as VelocyPack //////////////////////////////////////////////////////////////////////////////// -std::shared_ptr RestVocbaseBaseHandler::parseVelocyPackBody (bool& success) { +std::shared_ptr RestVocbaseBaseHandler::parseVelocyPackBody ( + VPackOptions const* options, + bool& success) { try { - VPackOptions options; - options.checkAttributeUniqueness = true; success = true; return _request->toVelocyPack(options); } diff --git a/arangod/RestHandler/RestVocbaseBaseHandler.h b/arangod/RestHandler/RestVocbaseBaseHandler.h index 8963a78707..d13d272e78 100644 --- a/arangod/RestHandler/RestVocbaseBaseHandler.h +++ b/arangod/RestHandler/RestVocbaseBaseHandler.h @@ -370,7 +370,7 @@ namespace triagens { /// @brief parses the body as VelocyPack //////////////////////////////////////////////////////////////////////////////// - std::shared_ptr parseVelocyPackBody (bool&); + std::shared_ptr parseVelocyPackBody (VPackOptions const*, bool&); //////////////////////////////////////////////////////////////////////////////// /// @brief parses a document handle, on a cluster this will parse the diff --git a/arangod/V8Server/v8-collection.cpp b/arangod/V8Server/v8-collection.cpp index 5d89553e00..7ca42988a0 100644 --- a/arangod/V8Server/v8-collection.cpp +++ b/arangod/V8Server/v8-collection.cpp @@ -713,11 +713,8 @@ static void ModifyVocbaseColCoordinator (TRI_vocbase_col_t const* collection, TRI_V8_THROW_EXCEPTION(error); } - TRI_json_t* json = TRI_ObjectToJson(isolate, args[1]); - if (! TRI_IsObjectJson(json)) { - if (json != nullptr) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } + std::unique_ptr json(TRI_ObjectToJson(isolate, args[1])); + if (! TRI_IsObjectJson(json.get())) { TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID); } @@ -730,7 +727,6 @@ static void ModifyVocbaseColCoordinator (TRI_vocbase_col_t const* collection, error = triagens::arango::modifyDocumentOnCoordinator( dbname, collname, key, rev, policy, waitForSync, isPatch, keepNull, mergeObjects, json, headers, responseCode, resultHeaders, resultBody); - // Note that the json has been freed inside! if (error != TRI_ERROR_NO_ERROR) { TRI_V8_THROW_EXCEPTION(error); @@ -738,40 +734,30 @@ static void ModifyVocbaseColCoordinator (TRI_vocbase_col_t const* collection, // report what the DBserver told us: this could now be 201/202 or // 400/404 - json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str()); + json.reset(TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str())); if (responseCode >= triagens::rest::HttpResponse::BAD) { - if (! TRI_IsObjectJson(json)) { - if (nullptr != json) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } + if (! TRI_IsObjectJson(json.get())) { TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL); } int errorNum = 0; - TRI_json_t* subjson = TRI_LookupObjectJson(json, "errorNum"); + TRI_json_t* subjson = TRI_LookupObjectJson(json.get(), "errorNum"); if (TRI_IsNumberJson(subjson)) { errorNum = static_cast(subjson->_value._number); } string errorMessage; - subjson = TRI_LookupObjectJson(json, "errorMessage"); + subjson = TRI_LookupObjectJson(json.get(), "errorMessage"); if (TRI_IsStringJson(subjson)) { errorMessage = string(subjson->_value._string.data, subjson->_value._string.length-1); } - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); TRI_V8_THROW_EXCEPTION_MESSAGE(errorNum, errorMessage); } if (silent) { - if (json != nullptr) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } TRI_V8_RETURN_TRUE(); } else { - v8::Handle ret = TRI_ObjectJson(isolate, json); - if (json != nullptr) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } + v8::Handle ret = TRI_ObjectJson(isolate, json.get()); TRI_V8_RETURN(ret); } } @@ -3209,11 +3195,8 @@ static void InsertVocbaseColCoordinator (TRI_vocbase_col_t* collection, options.waitForSync = ExtractWaitForSync(args, 2); } - TRI_json_t* json = TRI_ObjectToJson(isolate, args[0]); - if (! TRI_IsObjectJson(json)) { - if (json != nullptr) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } + std::unique_ptr json(TRI_ObjectToJson(isolate, args[0])); + if (! TRI_IsObjectJson(json.get())) { TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID); } @@ -3225,49 +3208,37 @@ static void InsertVocbaseColCoordinator (TRI_vocbase_col_t* collection, int error = triagens::arango::createDocumentOnCoordinator( dbname, collname, options.waitForSync, json, headers, responseCode, resultHeaders, resultBody); - // Note that the json has been freed inside! if (error != TRI_ERROR_NO_ERROR) { TRI_V8_THROW_EXCEPTION(error); } // report what the DBserver told us: this could now be 201/202 or // 400/404 - json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str()); + json.reset(TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str())); if (responseCode >= triagens::rest::HttpResponse::BAD) { - if (! TRI_IsObjectJson(json)) { - if (json != nullptr) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } + if (! TRI_IsObjectJson(json.get())) { TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL); } int errorNum = 0; - TRI_json_t* subjson = TRI_LookupObjectJson(json, "errorNum"); + TRI_json_t* subjson = TRI_LookupObjectJson(json.get(), "errorNum"); if (nullptr != subjson && TRI_IsNumberJson(subjson)) { errorNum = static_cast(subjson->_value._number); } string errorMessage; - subjson = TRI_LookupObjectJson(json, "errorMessage"); + subjson = TRI_LookupObjectJson(json.get(), "errorMessage"); if (nullptr != subjson && TRI_IsStringJson(subjson)) { errorMessage = string(subjson->_value._string.data, subjson->_value._string.length-1); } - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); TRI_V8_THROW_EXCEPTION_MESSAGE(errorNum, errorMessage); } if (options.silent) { - if (json != nullptr) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } TRI_V8_RETURN_TRUE(); } - v8::Handle ret = TRI_ObjectJson(isolate, json); - - if (json != nullptr) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } + v8::Handle ret = TRI_ObjectJson(isolate, json.get()); TRI_V8_RETURN(ret); } @@ -3479,12 +3450,9 @@ static void InsertEdgeColCoordinator (TRI_vocbase_col_t* collection, string _from = GetId(args, 0); string _to = GetId(args, 1); - TRI_json_t* json = TRI_ObjectToJson(isolate, args[2]); + std::unique_ptr json(TRI_ObjectToJson(isolate, args[2])); - if (! TRI_IsObjectJson(json)) { - if (json != nullptr) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } + if (! TRI_IsObjectJson(json.get())) { TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID); } @@ -3510,41 +3478,34 @@ static void InsertEdgeColCoordinator (TRI_vocbase_col_t* collection, string resultBody; int error = triagens::arango::createEdgeOnCoordinator( - dbname, collname, options.waitForSync, json, _from.c_str(), _to.c_str(), + dbname, collname, options.waitForSync, json, + _from.c_str(), _to.c_str(), responseCode, resultHeaders, resultBody); - // Note that the json has been freed inside! if (error != TRI_ERROR_NO_ERROR) { TRI_V8_THROW_EXCEPTION(error); } // report what the DBserver told us: this could now be 201/202 or // 400/404 - json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str()); + json.reset(TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str())); if (responseCode >= triagens::rest::HttpResponse::BAD) { - if (! TRI_IsObjectJson(json)) { - if (nullptr != json) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } + if (! TRI_IsObjectJson(json.get())) { TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL); } int errorNum = 0; - TRI_json_t* subjson = TRI_LookupObjectJson(json, "errorNum"); + TRI_json_t* subjson = TRI_LookupObjectJson(json.get(), "errorNum"); if (nullptr != subjson && TRI_IsNumberJson(subjson)) { errorNum = static_cast(subjson->_value._number); } string errorMessage; - subjson = TRI_LookupObjectJson(json, "errorMessage"); + subjson = TRI_LookupObjectJson(json.get(), "errorMessage"); if (nullptr != subjson && TRI_IsStringJson(subjson)) { errorMessage = string(subjson->_value._string.data, subjson->_value._string.length-1); } - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); TRI_V8_THROW_EXCEPTION_MESSAGE(errorNum, errorMessage); } - v8::Handle ret = TRI_ObjectJson(isolate, json); - if (nullptr != json) { - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); - } + v8::Handle ret = TRI_ObjectJson(isolate, json.get()); TRI_V8_RETURN(ret); } diff --git a/lib/Rest/HttpRequest.cpp b/lib/Rest/HttpRequest.cpp index f1c876b6aa..bff8e8260d 100644 --- a/lib/Rest/HttpRequest.cpp +++ b/lib/Rest/HttpRequest.cpp @@ -523,8 +523,8 @@ void HttpRequest::setHeader (char const* key, /// @brief gets the request body as VPackBuilder //////////////////////////////////////////////////////////////////////////////// -std::shared_ptr HttpRequest::toVelocyPack (VPackOptions const& options) { - VPackParser parser(&options); +std::shared_ptr HttpRequest::toVelocyPack (VPackOptions const* options) { + VPackParser parser(options); parser.parse(body()); return parser.steal(); } diff --git a/lib/Rest/HttpRequest.h b/lib/Rest/HttpRequest.h index c4aecb6070..3a3899afac 100644 --- a/lib/Rest/HttpRequest.h +++ b/lib/Rest/HttpRequest.h @@ -522,7 +522,7 @@ namespace triagens { /// @brief gets the request body as VelocyPackBuilder //////////////////////////////////////////////////////////////////////////////// - std::shared_ptr toVelocyPack (VPackOptions const&); + std::shared_ptr toVelocyPack (VPackOptions const*); //////////////////////////////////////////////////////////////////////////////// /// @brief gets the request body as TRI_json_t*