Skip to content

Commit

Permalink
[Bug] fix log buffer inital issue
Browse files Browse the repository at this point in the history
In exec_execute_message(), we should initalize the log buffer at
outermost layer. If not, crash may happen when trying to accessing
its data member.

This patch fixes the issue.
  • Loading branch information
ocean-dot-li authored and polardb-bot[bot] committed Nov 16, 2023
1 parent 871ea83 commit ef4db25
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/backend/tcop/postgres.c
Original file line number Diff line number Diff line change
Expand Up @@ -2354,13 +2354,17 @@ exec_execute_message(const char *portal_name, long max_rows)
pq_putemptymessage('s');
}

buf.data = NULL;

if (to_log)
{
/* POLAR: get errmsg params string, we must free it in the last */
// It needs to malloc and free twice, not so efficiency.
params_string = polar_get_errmsg_params(portalParams);

/* POLAR: inital buf used by logging info. */
initStringInfo(&buf);

if (polar_enable_log_search_path)
appendStringInfo(&buf, "/*polardb %s polardb*/ ", namespace_search_path);

Expand Down Expand Up @@ -2491,7 +2495,7 @@ exec_execute_message(const char *portal_name, long max_rows)
pfree(params_string);
/* POLAR end */

if (buf.data)
if (to_log && buf.data)
pfree(buf.data);

if (save_log_statement_stats)
Expand Down

0 comments on commit ef4db25

Please sign in to comment.