diff options
author | Daniel Gustafsson <dgustafsson@postgresql.org> | 2025-04-23 11:02:05 +0200 |
---|---|---|
committer | Daniel Gustafsson <dgustafsson@postgresql.org> | 2025-04-23 11:02:05 +0200 |
commit | 994a100b37ad8c2fb8282a9fce91a16b4c832277 (patch) | |
tree | b08a5e1e17d950c431d6b8c1c4ba3b84a1e81d83 /src/interfaces/libpq/fe-auth-oauth.c | |
parent | 0ff95e0a5be1372bfba9db284ea17c8e0e5da3a0 (diff) | |
download | postgresql-994a100b37ad8c2fb8282a9fce91a16b4c832277.tar.gz postgresql-994a100b37ad8c2fb8282a9fce91a16b4c832277.zip |
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 <daniel@yesql.se>
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/2074634.1744839761@sss.pgh.pa.us
Diffstat (limited to 'src/interfaces/libpq/fe-auth-oauth.c')
-rw-r--r-- | src/interfaces/libpq/fe-auth-oauth.c | 12 |
1 files changed, 6 insertions, 6 deletions
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; |