zhouqingqing / qpmodel

A Relational Optimizer and Executor
MIT License
66 stars 18 forks source link

memory fix for native code #303

Closed pkommoju closed 3 years ago

pkommoju commented 3 years ago

Tidy up the code.

Important Note: This is work in progress, has two or three memory leaks.

Hightlight of changes since last PR:

Fix a few memory leaks and tidy up the code.

All debug messages are under _DEBUG and a few other specific guards.

Skip optimzer test table creation. call delete on containers using simple loop (like singly linked list deletion).

Valgrind error about mismatched free/delete was legitimate but not quite obvious. delete of SQLStatement has no effect because it is called in the context where the pointer has incomplete type. Moving the destructor to stmt.cpp fixed it.

CRT Invalid pointer breakpoint problem is fixed. The problem is with for (auto it = pointers_.begin(); it != pointers_end); / /) pointerserase(it++); replacing it with auto itb = pointers.begin(); auto ite = pointers_end); while (itb != ite) pointers_erase(itb++); fixed.

Binder allocation are not realeased. Need to put that code back in.

Operators above PhysicScan own the rows returned to them, in spite of the comments and returning true/false from Exec giving this idea. If they have to own, they have to make their own copies. This is likely to change.

A Visual Leak Detector (VLD) is used by this branch. VLD is much better than MS CRT provided facilities but still a bit raw, but it is faster than what valgrind would be (There is no valgrind on Windows, though). VLD consists of src/common/vld.h, src/common/vld_def.h, ./out/build/x64-Debug/vld.lib and/or ./out/build/vld.lib dbghelp.dll, and vld_x64.dll in server/experimental. The headers are checked in common, but .lib and .dll are checked in server/make_tools

CMAKE json file has the following changes to make use of VLD but the INC and LIB directives did not work. VLD is enabled by these changes and #define __USEVLD is vld.h.

+      "ctestCommandArgs": "",
+      "variables": [
+        {
+          "name": "CMAKE_C_FLAGS_DEBUG",
+          "value": "/MDd /Zi /Ob0 /Od /RTC1",
+          "type": "STRING"
+        },
+        {
+          "name": "CMAKE_CXX_FLAGS_DEBUG",
+          "value": "/MDd /Zi /Ob0 /Od /RTC1  /I\"C:\\Program Files (x86)\\Visual Leak Detector\\include\"",
+          "type": "STRING"
+        },
+        {
+          "name": "CMAKE_EXE_LINKER_FLAGS_DEBUG",
+          "value": "/debug:FULL /INCREMENTAL /LIBPATH:\"C:\\Program Files (x86)\\Visual Leak Detector\\lib\\Win64\" /IMPLIB:vld.lib",
+          "type": "STRING"
+        }
+      ]
     },