Skip to content

Commit

Permalink
fix build on master (pg17+)
Browse files Browse the repository at this point in the history
  • Loading branch information
okbob committed Mar 4, 2024
1 parent 8e7b9c9 commit 7b0e28d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/cursors_leaks.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ typedef struct

MemoryContextCallback contextCallback;


static LocalTransactionId traces_lxid = InvalidLocalTransactionId;
static HTAB *traces = NULL;
static MemoryContext traces_mcxt = NULL;
Expand All @@ -60,14 +59,24 @@ static void stmt_end(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt, void **plugi
static plpgsql_check_plugin2 cursors_leaks_plugin2 = { func_setup, NULL, func_end, NULL,
NULL, stmt_end, NULL, NULL, NULL, NULL, NULL, NULL };

#if PG_VERSION_NUM >= 170000

#define CURRENT_LXID (MyProc->vxid.lxid)

#else

#define CURRENT_LXID (MyProc->lxid)

#endif

static FunctionTrace *
get_function_trace(PLpgSQL_function *func)
{
bool found;
FunctionTrace *ftrace;
FunctionTraceKey key;

if (traces == NULL || traces_lxid != MyProc->lxid)
if (traces == NULL || traces_lxid != CURRENT_LXID)
{
HASHCTL ctl;

Expand All @@ -85,7 +94,7 @@ get_function_trace(PLpgSQL_function *func)
&ctl,
HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);

traces_lxid = MyProc->lxid;
traces_lxid = CURRENT_LXID;
}

key.fn_oid = func->fn_oid;
Expand Down Expand Up @@ -132,7 +141,7 @@ func_end(PLpgSQL_execstate *estate,
FunctionTrace *ftrace = *plugin2_info;
int i;

if (!ftrace || traces_lxid != MyProc->lxid)
if (!ftrace || traces_lxid != CURRENT_LXID)
return;

for (i = 0; i < ftrace->ncursors; i++)
Expand Down Expand Up @@ -182,7 +191,7 @@ stmt_end(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt, void **plugin2_info)
if (!ftrace)
return;

if (traces_lxid != MyProc->lxid)
if (traces_lxid != CURRENT_LXID)
{
ftrace = get_function_trace(estate->func);
*plugin2_info = ftrace;
Expand Down

0 comments on commit 7b0e28d

Please sign in to comment.