[CP] fix the memleak of nested Array
This commit is contained in:
		
							
								
								
									
										12
									
								
								deps/oblib/src/lib/utility/utility.h
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								deps/oblib/src/lib/utility/utility.h
									
									
									
									
										vendored
									
									
								
							| @ -1057,15 +1057,23 @@ inline void set_member_allocator(T &dest, common::ObIAllocator *alloc) | |||||||
| template <typename T> | template <typename T> | ||||||
| inline int construct_assign_wrap(T &dest, const T &src, TrueType) | inline int construct_assign_wrap(T &dest, const T &src, TrueType) | ||||||
| { | { | ||||||
|  |   int ret = OB_SUCCESS; | ||||||
|   new(&dest) T(); |   new(&dest) T(); | ||||||
|   return dest.assign(src); |   if (OB_FAIL(dest.assign(src))) { | ||||||
|  |     dest.~T(); | ||||||
|  |   } | ||||||
|  |   return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename T> | template <typename T> | ||||||
| inline int construct_assign_wrap(T &dest, const T &src, FalseType) | inline int construct_assign_wrap(T &dest, const T &src, FalseType) | ||||||
| { | { | ||||||
|  |   int ret = OB_SUCCESS; | ||||||
|   new(&dest) T(src); |   new(&dest) T(src); | ||||||
|   return get_copy_assign_ret_wrap(dest, BoolType<HAS_MEMBER(T, get_copy_assign_ret)>()); |   if (OB_FAIL(get_copy_assign_ret_wrap(dest, BoolType<HAS_MEMBER(T, get_copy_assign_ret)>()))) { | ||||||
|  |     dest.~T(); | ||||||
|  |   } | ||||||
|  |   return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| // This function is used for copy assignment | // This function is used for copy assignment | ||||||
|  | |||||||
							
								
								
									
										26
									
								
								deps/oblib/unittest/lib/utility/test_utility.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										26
									
								
								deps/oblib/unittest/lib/utility/test_utility.cpp
									
									
									
									
										vendored
									
									
								
							| @ -18,6 +18,32 @@ | |||||||
| using namespace oceanbase::common; | using namespace oceanbase::common; | ||||||
| using namespace std; | using namespace std; | ||||||
|  |  | ||||||
|  | struct TestItem | ||||||
|  | { | ||||||
|  |   TestItem() : status_(0), disable_assign_(false) | ||||||
|  |   {} | ||||||
|  |   ~TestItem() | ||||||
|  |   { | ||||||
|  |     status_ = 1; | ||||||
|  |   } | ||||||
|  |   int assign(const TestItem &other) | ||||||
|  |   { | ||||||
|  |     return other.disable_assign_ ? OB_ERROR : OB_SUCCESS; | ||||||
|  |   } | ||||||
|  |   int status_; | ||||||
|  |   bool disable_assign_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | TEST(utility, construct_assign) | ||||||
|  | { | ||||||
|  |   TestItem item_1, item_2; | ||||||
|  |   item_1.disable_assign_ = true; | ||||||
|  |   TestItem *item = (TestItem *)ob_malloc(sizeof(TestItem), "TEST"); | ||||||
|  |   construct_assign(*item, item_1); | ||||||
|  |   ASSERT_EQ(1, item->status_); | ||||||
|  |   construct_assign(*item, item_2); | ||||||
|  |   ASSERT_EQ(0, item->status_); | ||||||
|  | } | ||||||
|  |  | ||||||
| TEST(utility, load_file_to_string) | TEST(utility, load_file_to_string) | ||||||
| { | { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 obdev
					obdev