Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for cache reference leak warning #3161

Open
wants to merge 24 commits into
base: BABEL_4_X_DEV
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/composite-actions/install-extensions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ runs:
if [[ ${{ inputs.server_collation_name }} != "default" ]]; then
sudo echo "babelfishpg_tsql.server_collation_name = '${{ inputs.server_collation_name }}'" >> postgresql.conf
fi
~/${{inputs.install_dir}}/bin/pg_ctl -c -D ~/${{inputs.install_dir}}/$DATADIR/ -l logfile start
~/${{inputs.install_dir}}/bin/pg_ctl -c -D ~/${{inputs.install_dir}}/$DATADIR/ -l ~/${{inputs.install_dir}}/$DATADIR/logfile start
cd ~/work/babelfish_extensions/babelfish_extensions/
sudo ~/${{inputs.install_dir}}/bin/psql -v ON_ERROR_STOP=1 -d postgres -U runner -p ${{inputs.psql_port}} -v user="jdbc_user" -v db="babelfish_db" -v migration_mode=${{inputs.migration_mode}} -v tsql_port=${{inputs.tsql_port}} -v parallel_query_mode=${{inputs.parallel_query_mode}} -f .github/scripts/create_extension.sql
~/${{inputs.install_dir}}/bin/pg_ctl -c -D ~/${{inputs.install_dir}}/$DATADIR/ -l logfile restart
~/${{inputs.install_dir}}/bin/pg_ctl -c -D ~/${{inputs.install_dir}}/$DATADIR/ -l ~/${{inputs.install_dir}}/$DATADIR/logfile restart
sqlcmd -S localhost,${{inputs.tsql_port}} -U "jdbc_user" -P 12345678 -Q "SELECT @@version GO"
shell: bash
24 changes: 19 additions & 5 deletions contrib/babelfishpg_tsql/src/pl_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,7 @@ bbf_ProcessUtility(PlannedStmt *pstmt,
bool with_recompile = false;
Node *tbltypStmt = NULL;
ListCell *parameter;
HeapTuple proctup;

cfs = makeNode(CreateFunctionStmt);
cfs->returnType = NULL;
Expand Down Expand Up @@ -2600,13 +2601,26 @@ bbf_ProcessUtility(PlannedStmt *pstmt,
originalFunc.objectId = oldoid;
originalFunc.classId = ProcedureRelationId;
originalFunc.objectSubId = 0;
if(get_bbf_function_tuple_from_proctuple(SearchSysCache1(PROCOID, ObjectIdGetDatum(oldoid))) == NULL)
proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(oldoid));

if (proctup == NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use HeapTupleIsValid & curly braces can be removed in next line.

{
/* Detect PSQL functions and throw error */
ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("No existing TSQL procedure found with the name for ALTER PROCEDURE")));
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("cache lookup failed for procedure %u", oldoid)));
}
if (get_bbf_function_tuple_from_proctuple(proctup) == NULL)
{
/* Release the tuple before reporting the error */
ReleaseSysCache(proctup);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of error we do not need to release syscache


/* Detect PSQL functions and throw error */
ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("No existing TSQL procedure found with the name for ALTER PROCEDURE")));
}
ReleaseSysCache(proctup);

if(!cfs->is_procedure)
{
/*
Expand Down