Skip to content

Commit

Permalink
[CP] [to #56902916] fix memory leak with collect result & dbms cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
obdev authored and ob-robot committed May 27, 2024
1 parent 3d8fe84 commit 87ff6e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/sql/ob_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7622,6 +7622,12 @@ int ObSPIService::get_result(ObPLExecCtx *ctx,
ret = OB_SUCCESS;
} else {
LOG_WARN("read result error", K(ret));
for (int64_t i = 0; i < tmp_result.count(); ++i) {
int tmp_ret = OB_SUCCESS;
if ((tmp_ret = ObUserDefinedType::destruct_obj(tmp_result.at(i), ctx->exec_ctx_->get_my_session())) != OB_SUCCESS) {
LOG_WARN("failed to destruct obj, memory may leak", K(ret), K(tmp_ret), K(i));
}
}
}
}
OX (bulk_tables.reuse());
Expand Down
3 changes: 3 additions & 0 deletions src/sql/session/ob_sql_session_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1634,18 +1634,21 @@ int ObSQLSessionInfo::close_dbms_cursor(int64_t cursor_id)
{
int ret = OB_SUCCESS;
ObPLCursorInfo *cursor = NULL;
ObDbmsCursorInfo *dbms_cursor = NULL;
LOG_INFO("remove dbms cursor", K(ret), K(cursor_id), K(get_sessid()));
// when select GV$OPEN_CURSOR, we will add get_thread_data_lock to fetch pl_cursor_map_
// so we need get_thread_data_lock there
ObSQLSessionInfo::LockGuard lock_guard(get_thread_data_lock());
OZ (pl_cursor_cache_.pl_cursor_map_.erase_refactored(cursor_id, &cursor), cursor_id);
OV (OB_NOT_NULL(cursor), OB_ERR_UNEXPECTED, cursor_id);
OV (OB_NOT_NULL(dbms_cursor = static_cast<ObDbmsCursorInfo *>(cursor)), OB_ERR_UNEXPECTED, cursor_id);
if (OB_SUCC(ret) && lib::is_diagnose_info_enabled()) {
EVENT_DEC(SQL_OPEN_CURSORS_CURRENT);
}
// dbms cursor应该先执行spi接口关闭,再执行session接口删除。
OV (!cursor->isopen(), OB_ERR_UNEXPECTED, cursor_id);
OX (cursor->reset());
OX (dbms_cursor->~ObDbmsCursorInfo());
OX (get_cursor_allocator().free(cursor));
OX (cursor = NULL);
return ret;
Expand Down

0 comments on commit 87ff6e0

Please sign in to comment.