[to #53220315] fix opaque deep copy memory leak

This commit is contained in:
obdev
2024-04-03 09:20:17 +00:00
committed by ob-robot
parent c82292eb5f
commit 02281e1d23

View File

@ -8803,6 +8803,7 @@ int ObSPIService::spi_copy_opaque(
ObPLOpaque &src, ObPLOpaque *&dest, uint64_t package_id) ObPLOpaque &src, ObPLOpaque *&dest, uint64_t package_id)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
bool is_new_opaque = false;
UNUSEDx(ctx, package_id); UNUSEDx(ctx, package_id);
if (NULL == dest) { if (NULL == dest) {
CK (OB_NOT_NULL(allocator)); CK (OB_NOT_NULL(allocator));
@ -8811,6 +8812,7 @@ int ObSPIService::spi_copy_opaque(
LOG_WARN("failed to alloc memory for dest opaque", K(ret), K(src.get_init_size())); LOG_WARN("failed to alloc memory for dest opaque", K(ret), K(src.get_init_size()));
} }
OX (new (dest)ObPLOpaque()); OX (new (dest)ObPLOpaque());
OX (is_new_opaque = true);
} }
if (OB_SUCC(ret)) { if (OB_SUCC(ret)) {
switch (src.get_type()) { switch (src.get_type()) {
@ -8834,6 +8836,10 @@ int ObSPIService::spi_copy_opaque(
OZ (src.deep_copy(dest)); OZ (src.deep_copy(dest));
} break; } break;
} }
if (OB_FAIL(ret) && is_new_opaque) {
dest->~ObPLOpaque();
dest = NULL;
}
} }
return ret; return ret;
} }