]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2272] Replaced malloc with new in command options helper.
authorMarcin Siodelski <marcin@isc.org>
Thu, 20 Sep 2012 11:25:35 +0000 (13:25 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 20 Sep 2012 11:25:35 +0000 (13:25 +0200)
tests/tools/perfdhcp/tests/command_options_helper.h

index 860a040fd385c83131f42fbccd125e2c258c5c5a..d1d1fb4e4f1f8d7d95731081567998b1ec03d30d 100644 (file)
@@ -57,10 +57,10 @@ public:
         ~ArgvPtr() {
             if (argv_ != NULL) {
                 for(int i = 0; i < argc_; ++i) {
-                    free(argv_[i]);
+                    delete[] (argv_[i]);
                     argv_[i] = NULL;
                 }
-                free(argv_);
+                delete[] (argv_);
             }
         }
 
@@ -115,14 +115,15 @@ private:
 
         if (tokens.size() > 0) {
             // Allocate array of C-strings where we will store tokens
-            results = static_cast<char**>(malloc(tokens.size() * sizeof(char*)));
-            if (results == NULL) {
-                isc_throw(Unexpected, "unable to allocate array of c-strings");
-            }
+            results = new (std::nothrow) char*[tokens.size() * sizeof(char*)];
+            assert(results != NULL);
             // Store tokens in C-strings array
             for (int i = 0; i < tokens.size(); ++i) {
-                char* cs = static_cast<char*>(malloc(tokens[i].length() + 1));
-                strcpy(cs, tokens[i].c_str());
+                size_t cs_size = tokens[i].length() + 1;
+                char* cs = new (std::nothrow) char[cs_size];
+                assert (cs != NULL);
+                strncpy(cs, tokens[i].c_str(), cs_size);
+                assert(cs[cs_size - 1] == '\0');
                 results[i] = cs;
             }
             // Return number of tokens to calling function