From bd47ba2a6d293289382e59c5c1c15b8d227b7dcf Mon Sep 17 00:00:00 2001 From: neverchanje Date: Mon, 15 Oct 2018 16:01:02 +0800 Subject: [PATCH] fix valgrind warnings ==11454== ==11454== Conditional jump or move depends on uninitialised value(s) ==11454== at 0x4601EC: i64toa (itoa.h:293) ==11454== by 0x4601EC: WriteInt64 (writer.h:301) ==11454== by 0x4601EC: rapidjson::Writer, rapidjson::UTF8, rapidjson::UTF8, rapidjson::CrtAllocator, 0u>::Int64(long) (writer.h:176) ==11454== by 0x464085: json_encode (json_helper.h:271) ==11454== by 0x464085: encode_inner (json_helper.h:517) ==11454== by 0x464085: encode (json_helper.h:541) ==11454== by 0x464085: encode_json_state (replica_context.h:228) ==11454== by 0x464085: encode_inner (json_helper.h:505) ==11454== by 0x464085: encode (json_helper.h:541) ==11454== by 0x464085: encode (json_helper.h:547) ==11454== by 0x464085: dsn::json::json_forwarder::encode(dsn::replication::cold_backup_metadata const&) (json_helper.h:552) ==11454== by 0x45D3F5: replication_service_test_app::read_backup_metadata_test() (cold_backup_context_test.cpp:230) ==11454== by 0x494365: void testing::internal::HandleSehExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) (in /home/mi/git/release/pegasus/rdsn/builder/src/dist/replication/test/replica_test/unit_test/dsn.replica.test) ==11454== by 0x48E125: void testing::internal::HandleExceptionsInMethodIfSupported(testing::Test*, void (testing::Test::*)(), char const*) (in /home/mi/git/release/pegasus/rdsn/builder/src/dist/replication/test/replica_test/unit_test/dsn.replica.test) ==11454== by 0x473EBE: testing::Test::Run() (in /home/mi/git/release/pegasus/rdsn/builder/src/dist/replication/test/replica_test/unit_test/dsn.replica.test) ==11454== by 0x474747: testing::TestInfo::Run() (in /home/mi/git/release/pegasus/rdsn/builder/src/dist/replication/test/replica_test/unit_test/dsn.replica.test) ==11454== by 0x474DD7: testing::TestCase::Run() (in /home/mi/git/release/pegasus/rdsn/builder/src/dist/replication/test/replica_test/unit_test/dsn.replica.test) ==11454== by 0x47B51B: testing::internal::UnitTestImpl::RunAllTests() (in /home/mi/git/release/pegasus/rdsn/builder/src/dist/replication/test/replica_test/unit_test/dsn.replica.test) ==11454== by 0x495743: bool testing::internal::HandleSehExceptionsInMethodIfSupported(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (in /home/mi/git/release/pegasus/rdsn/builder/src/dist/replication/test/replica_test/unit_test/dsn.replica.test) ==11454== by 0x48EF1B: bool testing::internal::HandleExceptionsInMethodIfSupported(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (in /home/mi/git/release/pegasus/rdsn/builder/src/dist/replication/test/replica_test/unit_test/dsn.replica.test) ==11454== by 0x47A1AD: testing::UnitTest::Run() (in /home/mi/git/release/pegasus/rdsn/builder/src/dist/replication/test/replica_test/unit_test/dsn.replica.test) ==11454== --- include/dsn/cpp/json_helper.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/dsn/cpp/json_helper.h b/include/dsn/cpp/json_helper.h index 3062df9687..feeaf712f9 100644 --- a/include/dsn/cpp/json_helper.h +++ b/include/dsn/cpp/json_helper.h @@ -550,10 +550,7 @@ class json_forwarder { std::ostringstream os; encode(os, t); - std::string *result = new std::string(os.str()); - return dsn::blob(std::shared_ptr(const_cast(result->c_str()), - [result](char *) { delete result; }), - result->length()); + return blob::create_from_bytes(os.str()); } static bool decode(const JsonObject &in, T &t)