You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by is...@apache.org on 2019/01/22 09:48:53 UTC

[ignite] branch master updated: IGNITE-10981: Fixed heap memory corruption in C++

This is an automated email from the ASF dual-hosted git repository.

isapego pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new bfbbe21  IGNITE-10981: Fixed heap memory corruption in C++
bfbbe21 is described below

commit bfbbe21ea58655085b4bd2936a135fa8a4314dc4
Author: Igor Sapego <is...@apache.org>
AuthorDate: Tue Jan 22 12:47:36 2019 +0300

    IGNITE-10981: Fixed heap memory corruption in C++
---
 modules/platforms/cpp/core/src/ignition.cpp | 46 ++++++++++-------------------
 1 file changed, 16 insertions(+), 30 deletions(-)

diff --git a/modules/platforms/cpp/core/src/ignition.cpp b/modules/platforms/cpp/core/src/ignition.cpp
index 3891be1..f81215c 100644
--- a/modules/platforms/cpp/core/src/ignition.cpp
+++ b/modules/platforms/cpp/core/src/ignition.cpp
@@ -75,8 +75,7 @@ namespace ignite
          * Constructor.
          */
         JvmOptions() :
-            size(0),
-            opts(0)
+            opts()
         {
             // No-op.
         }
@@ -100,16 +99,9 @@ namespace ignite
         {
             Deinit();
 
-            size = 3 + static_cast<int>(cfg.jvmOpts.size());
+            const size_t REQ_OPTS_CNT = 4;
 
-            if (!home.empty())
-                ++size;
-
-            // Brackets '()' here guarantee for the array to be zeroed.
-            // Important to avoid crash in case of exception.
-            opts = new char*[size]();
-
-            int idx = 0;
+            opts.reserve(cfg.jvmOpts.size() + REQ_OPTS_CNT);
 
             std::string fileEncParam = "-Dfile.encoding=";
 
@@ -118,35 +110,35 @@ namespace ignite
             // 1. Set classpath.
             std::string cpFull = "-Djava.class.path=" + cp;
 
-            opts[idx++] = CopyChars(cpFull.c_str());
+            opts.push_back(CopyChars(cpFull.c_str()));
 
             // 2. Set home.
             if (!home.empty()) {
                 std::string homeFull = "-DIGNITE_HOME=" + home;
 
-                opts[idx++] = CopyChars(homeFull.c_str());
+                opts.push_back(CopyChars(homeFull.c_str()));
             }
 
             // 3. Set Xms, Xmx.
             std::string xmsStr = JvmMemoryString("-Xms", cfg.jvmInitMem);
             std::string xmxStr = JvmMemoryString("-Xmx", cfg.jvmMaxMem);
 
-            opts[idx++] = CopyChars(xmsStr.c_str());
-            opts[idx++] = CopyChars(xmxStr.c_str());
+            opts.push_back(CopyChars(xmsStr.c_str()));
+            opts.push_back(CopyChars(xmxStr.c_str()));
 
             // 4. Set the rest options.
             for (std::list<std::string>::const_iterator i = cfg.jvmOpts.begin(); i != cfg.jvmOpts.end(); ++i) {
                 if (i->find(fileEncParam) != std::string::npos)
                     hadFileEnc = true;
 
-                opts[idx++] = CopyChars(i->c_str());
+                opts.push_back(CopyChars(i->c_str()));
             }
 
             // 5. Set file.encoding.
             if (!hadFileEnc) {
                 std::string fileEncFull = fileEncParam + "UTF-8";
 
-                opts[idx++] = CopyChars(fileEncFull.c_str());
+                opts.push_back(CopyChars(fileEncFull.c_str()));
             }
         }
 
@@ -155,13 +147,10 @@ namespace ignite
          */
         void Deinit()
         {
-            if (opts)
-            {
-                for (int i = 0; i < size; ++i)
-                    ReleaseChars(opts[i]);
+            for (size_t i = 0; i < opts.size(); ++i)
+                ReleaseChars(opts[i]);
 
-                delete[] opts;
-            }
+            opts.clear();
         }
 
         /**
@@ -169,9 +158,9 @@ namespace ignite
          *
          * @return Built options
          */
-        char** GetOpts() const
+        char** GetOpts()
         {
-            return opts;
+            return &opts[0];
         }
 
         /**
@@ -181,15 +170,12 @@ namespace ignite
          */
         int GetSize() const
         {
-            return size;
+            return static_cast<int>(opts.size());
         }
 
     private:
-        /** Size */
-        int size;
-
         /** Options array. */
-        char** opts;
+        std::vector<char*> opts;
     };
 
     Ignite Ignition::Start(const IgniteConfiguration& cfg)