From 994a100b37ad8c2fb8282a9fce91a16b4c832277 Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Wed, 23 Apr 2025 11:02:05 +0200 Subject: Allocate JsonLexContexts on the heap to avoid warnings The stack allocated JsonLexContexts, in combination with codepaths using goto, were causing warnings when compiling with LTO enabled as the optimizer is unable to figure out that is safe. Rather than contort the code with workarounds for this simply heap allocate the structs instead as these are not in any performance critical paths. Author: Daniel Gustafsson Reported-by: Tom Lane Reviewed-by: Jacob Champion Reviewed-by: Tom Lane Discussion: https://postgr.es/m/2074634.1744839761@sss.pgh.pa.us --- src/interfaces/libpq/fe-auth-oauth.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/interfaces/libpq/fe-auth-oauth.c') diff --git a/src/interfaces/libpq/fe-auth-oauth.c b/src/interfaces/libpq/fe-auth-oauth.c index cf1a25e2ccc..ab6a45e2aba 100644 --- a/src/interfaces/libpq/fe-auth-oauth.c +++ b/src/interfaces/libpq/fe-auth-oauth.c @@ -476,7 +476,7 @@ issuer_from_well_known_uri(PGconn *conn, const char *wkuri) static bool handle_oauth_sasl_error(PGconn *conn, const char *msg, int msglen) { - JsonLexContext lex = {0}; + JsonLexContext *lex; JsonSemAction sem = {0}; JsonParseErrorType err; struct json_ctx ctx = {0}; @@ -504,8 +504,8 @@ handle_oauth_sasl_error(PGconn *conn, const char *msg, int msglen) return false; } - makeJsonLexContextCstringLen(&lex, msg, msglen, PG_UTF8, true); - setJsonLexContextOwnsTokens(&lex, true); /* must not leak on error */ + lex = makeJsonLexContextCstringLen(NULL, msg, msglen, PG_UTF8, true); + setJsonLexContextOwnsTokens(lex, true); /* must not leak on error */ initPQExpBuffer(&ctx.errbuf); sem.semstate = &ctx; @@ -516,7 +516,7 @@ handle_oauth_sasl_error(PGconn *conn, const char *msg, int msglen) sem.array_start = oauth_json_array_start; sem.scalar = oauth_json_scalar; - err = pg_parse_json(&lex, &sem); + err = pg_parse_json(lex, &sem); if (err == JSON_SEM_ACTION_FAILED) { @@ -535,7 +535,7 @@ handle_oauth_sasl_error(PGconn *conn, const char *msg, int msglen) } } else if (err != JSON_SUCCESS) - errmsg = json_errdetail(err, &lex); + errmsg = json_errdetail(err, lex); if (errmsg) libpq_append_conn_error(conn, @@ -544,7 +544,7 @@ handle_oauth_sasl_error(PGconn *conn, const char *msg, int msglen) /* Don't need the error buffer or the JSON lexer anymore. */ termPQExpBuffer(&ctx.errbuf); - freeJsonLexContext(&lex); + freeJsonLexContext(lex); if (errmsg) goto cleanup; -- cgit v1.2.3