提交 5462fd51 编写于 作者: S stdliu 提交者: wangzelin.wzl

Fix inner sql execution refered to destroyed SQL bug

上级 ef6137fe
......@@ -61,8 +61,21 @@ public:
virtual int execute(sql::ObSql& engine, sql::ObSqlCtx& ctx, sql::ObResultSet& res)
{
observer::ObReqTimeGuard req_timeinfo_guard;
res.get_session().store_query_string(sql_);
return engine.stmt_query(sql_, ctx, res);
int ret = OB_SUCCESS;
// Deep copy sql, because sql may be destroyed before result iteration.
const int64_t alloc_size = sizeof(ObString) + sql_.length() + 1; // 1 for C terminate char
void *mem = res.get_mem_pool().alloc(alloc_size);
if (NULL == mem) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("allocate memory failed", K(ret));
} else {
ObString *dup_sql = new (mem) ObString(sql_.length(), sql_.length(), static_cast<char *>(mem) + sizeof(ObString));
MEMCPY(dup_sql->ptr(), sql_.ptr(), sql_.length());
dup_sql->ptr()[sql_.length()] = '\0';
res.get_session().store_query_string(*dup_sql);
ret = engine.stmt_query(sql_, ctx, res);
}
return ret;
}
// process result after result open
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册