Skip to content

Commit

Permalink
fix valgrind warning in pltsql_store_view_definition (#3019)
Browse files Browse the repository at this point in the history
Reset static variable original_query_string back to NULL after use otherwise next queries which do not set original_query_string in ANLTR will read already freed memory.
---------
Signed-off-by: Tanzeel Khan <[email protected]>
  • Loading branch information
tanscorpio7 authored Oct 14, 2024
1 parent 563e51d commit 95dbb0b
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions contrib/babelfishpg_tsql/src/pl_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -4633,8 +4633,7 @@ exec_stmt_execsql(PLtsql_execstate *estate,
(estate->func->fn_is_trigger == PLTSQL_NOT_TRIGGER) &&
(strcmp(estate->func->fn_signature, "inline_code_block") != 0);

if (stmt->original_query)
original_query_string = stmt->original_query;
original_query_string = stmt->original_query ? stmt->original_query : NULL;

if (stmt->is_cross_db)
{
Expand Down Expand Up @@ -4668,15 +4667,15 @@ exec_stmt_execsql(PLtsql_execstate *estate,
{
int ret = exec_stmt_insert_execute_select(estate, expr);

if (stmt->is_cross_db)
{
if (stmt->schema_name != NULL && (strcmp(stmt->schema_name, "sys") == 0 || strcmp(stmt->schema_name, "information_schema") == 0))
set_session_properties(cur_dbname);
}
if (reset_session_properties)
{
set_session_properties(cur_dbname);
}
else if (stmt->is_cross_db)
{
if (stmt->schema_name != NULL && (strcmp(stmt->schema_name, "sys") == 0 || strcmp(stmt->schema_name, "information_schema") == 0))
set_session_properties(cur_dbname);
}
return ret;
}

Expand Down Expand Up @@ -5070,8 +5069,10 @@ exec_stmt_execsql(PLtsql_execstate *estate,
restore_session_properties();
}
}
PG_CATCH();
PG_FINALLY();
{
original_query_string = NULL;

if (need_path_reset)
(void) set_config_option("search_path", old_search_path,
PGC_USERSET, PGC_S_SESSION,
Expand All @@ -5080,28 +5081,15 @@ exec_stmt_execsql(PLtsql_execstate *estate,
{
set_session_properties(cur_dbname);
}
if (stmt->is_cross_db)
else if (stmt->is_cross_db)
{
if (stmt->schema_name != NULL && (strcmp(stmt->schema_name, "sys") == 0 || strcmp(stmt->schema_name, "information_schema") == 0))
set_session_properties(cur_dbname);
}
PG_RE_THROW();
}
PG_END_TRY();

if (need_path_reset)
(void) set_config_option("search_path", old_search_path,
PGC_USERSET, PGC_S_SESSION,
GUC_ACTION_SAVE, true, 0, false);
if (reset_session_properties)
{
set_session_properties(cur_dbname);
}
if (stmt->is_cross_db)
{
if (stmt->schema_name != NULL && (strcmp(stmt->schema_name, "sys") == 0 || strcmp(stmt->schema_name, "information_schema") == 0))
set_session_properties(cur_dbname);
pfree(cur_dbname);
}
PG_END_TRY();

return PLTSQL_RC_OK;
}
Expand Down

0 comments on commit 95dbb0b

Please sign in to comment.