You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/05/07 03:05:28 UTC

[iotdb] branch jira1286 created (now a756309)

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

haonan pushed a change to branch jira1286
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at a756309  [IOTDB-1286] fix 4 C++ mem-leak points (#2976)

This branch includes the following new commits:

     new a756309  [IOTDB-1286] fix 4 C++ mem-leak points (#2976)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[iotdb] 01/01: [IOTDB-1286] fix 4 C++ mem-leak points (#2976)

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch jira1286
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit a756309b4f29f4923a05b443cf39a408ef13fb20
Author: Jamber <ja...@sina.com>
AuthorDate: Fri May 7 11:00:37 2021 +0800

    [IOTDB-1286] fix 4 C++ mem-leak points (#2976)
    
    Co-authored-by: haiyi.zb <ha...@alibaba-inc.com>
---
 client-cpp/src/main/Session.cpp | 11 +++++++----
 client-cpp/src/main/Session.h   | 16 ++++++++--------
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/client-cpp/src/main/Session.cpp b/client-cpp/src/main/Session.cpp
index dccf784..8cc696b 100644
--- a/client-cpp/src/main/Session.cpp
+++ b/client-cpp/src/main/Session.cpp
@@ -100,7 +100,7 @@ void Tablet::reset() {
 
 void Tablet::createColumns() {
     // create timestamp column
-    timestamps = new int64_t[maxRowNumber];
+    timestamps.resize(maxRowNumber);
     // create value columns
     values.resize(schemas.size());
     for (int i = 0; i < schemas.size(); i++) {
@@ -390,13 +390,15 @@ void Session::sortTablet(Tablet& tablet) {
     }
 
     this->sortIndexByTimestamp(index, tablet.timestamps, tablet.rowSize);
-    sort(tablet.timestamps, tablet.timestamps + tablet.rowSize);
+    sort(tablet.timestamps.begin(), tablet.timestamps.begin() + tablet.rowSize);
     for (int i = 0; i < tablet.schemas.size(); i++) {
         tablet.values[i] = sortList(tablet.values[i], index, tablet.rowSize);
     }
+
+    delete[] index;
 }
 
-void Session::sortIndexByTimestamp(int* index, int64_t* timestamps, int length) {
+void Session::sortIndexByTimestamp(int* index, std::vector<int64_t>& timestamps, int length) {
     // Use Insert Sort Algorithm
     if (length >= 2) {
         for (int i = 1; i < length; i++) {
@@ -709,11 +711,12 @@ void Session::insertRecordsOfOneDevice(string deviceId, vector<int64_t>& times,
             index[i] = i;
         }
 
-        this->sortIndexByTimestamp(index, times.data(), times.size());
+        this->sortIndexByTimestamp(index, times, times.size());
         sort(times.begin(), times.end());
         measurementsList = sortList(measurementsList, index, times.size());
         typesList = sortList(typesList, index, times.size());
         valuesList = sortList(valuesList, index, times.size());
+        delete[] index;
     }
     unique_ptr<TSInsertRecordsOfOneDeviceReq> request(new TSInsertRecordsOfOneDeviceReq());
     request->__set_sessionId(sessionId);
diff --git a/client-cpp/src/main/Session.h b/client-cpp/src/main/Session.h
index 4e8aba7..62995a4 100644
--- a/client-cpp/src/main/Session.h
+++ b/client-cpp/src/main/Session.h
@@ -16,10 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
- 
+
 #include <string>
 #include <vector>
-#include <exception> 
+#include <exception>
 #include <iostream>
 #include <algorithm>
 #include <map>
@@ -52,7 +52,7 @@ class IoTDBConnectionException : public std::exception
         IoTDBConnectionException() : message() {}
         IoTDBConnectionException(const char* m) : message(m) {}
         IoTDBConnectionException(std::string m) : message(m) {}
-        virtual const char* what() const throw () 
+        virtual const char* what() const throw ()
         {
             return message.c_str();
         }
@@ -76,7 +76,7 @@ public:
     std::vector<TSStatus> statusList;
 private:
     std::string message;
-    
+
 };
 
 class UnSupportedDataTypeException : public std::exception
@@ -368,7 +368,7 @@ private:
 public:
     std::string deviceId; // deviceId of this tablet
     std::vector<std::pair<std::string, TSDataType::TSDataType>> schemas; // the list of measurement schemas for creating the tablet
-    int64_t* timestamps;   //timestamps in this tablet
+    std::vector <int64_t> timestamps;   //timestamps in this tablet
     std::vector<std::vector<std::string>> values;
     int rowSize;    //the number of rows to include in this tablet
     int maxRowNumber;   // the maximum number of rows for this tablet
@@ -401,7 +401,7 @@ public:
         this->maxRowNumber = maxRowNumber;
 
         // create timestamp column
-        timestamps = new int64_t[maxRowNumber];
+        timestamps.resize(maxRowNumber);
         // create value columns
         values.resize(schemas.size());
         for (int i = 0; i < schemas.size(); i++) {
@@ -525,7 +525,7 @@ private:
     RowRecord rowRecord;
     char* currentBitmap; // used to cache the current bitmap for every column
     static const int flag = 0x80; // used to do `or` operation with bitmap to judge whether the value is null
-    
+
 public:
     SessionDataSet(){}
     SessionDataSet(std::string sql, std::vector<std::string>& columnNameList, std::vector<std::string>& columnTypeList, int64_t queryId,
@@ -594,7 +594,7 @@ class Session
         bool checkSorted(Tablet& tablet);
         bool checkSorted(std::vector<int64_t>& times);
         void sortTablet(Tablet& tablet);
-        void sortIndexByTimestamp(int* index, int64_t* timestamps, int length);
+        void sortIndexByTimestamp(int *index, std::vector<int64_t>& timestamps, int length);
         std::string getTimeZone();
         void setTimeZone(std::string zoneId);
         void appendValues(std::string &buffer, char* value, int size);