Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w630r-003taK-13 for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Mar 2026 08:57:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w630p-008XRe-1i for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Mar 2026 08:57:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w630p-008XRW-0n for pgsql-bugs@lists.postgresql.org; Fri, 27 Mar 2026 08:57:51 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w630n-00000001I23-3zc6 for pgsql-bugs@lists.postgresql.org; Fri, 27 Mar 2026 08:57:50 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-35a09e0dd63so1833886a91.3 for ; Fri, 27 Mar 2026 01:57:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774601869; cv=none; d=google.com; s=arc-20240605; b=NTxGb63oTStXKFiet6Qc6D9JylGCXI/OANASkvNp7GbQlEtAebzzQjgRbwUTdFnOYo +V1ad7SHjBfBP7jJMtIKzYPwrDr0vG6iHqGyHZmmwmZ/2aO2MAL54PQ8s3s4DiNF+FSp k1STFY5l8HLgYsFUm7bHZAXh1qMaE3orwoE9mfTNVvY2p3yFnz63F4MZqudwfLUfV4Cp zzJTVUAbpviPFlhelgPQH3dmtZxs5I3QqSzZuAGrTfeBeE2JLroj19WnMJSdU3N9Fa5w x+32kB1JvQlmgKm2Jr15k808mtsYrCkjOutlhbv0wkN4RTEJ3BBmJuR95JsmdrXDrJ5i R0qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=pk6EZMhmgrzb7jNWyt/7nAovGzWtOSfwxA/NH1FTYXY=; fh=FUwiX9tgFDG63rl2dDzLlOp40LzfrHJz0pZEqszcXQw=; b=CMNiNt8U7sz0KwEL2ag8XNvpLOE/8/41+RhIp6ctBRux9QMJfjb1jRCnBHJQbN7TBe /fZaBC2YVEL6AEXq9qAstox8o4X+8w+c45fHyKv8+QvH6jzO1vJBz7sloKKkkfk1W9uz sT9vTHp2f/KquMOaGQMU8sxNAmMWjk9J7nhdlrChaeuoYNJOET92gS1sECt04CKi9Dqi LwZZo0+9Stl2/oue9xHeDxj9GPoL+c/8QPWciXZA61oDEa17ODq5f8z2f7YSduQRqkU1 CUBWvMBdMeyGbSHhvLj5IR+L7abhHwk5Zm6ZrqS/9G7t5DqKB0V6RpXgRKH1NcYDTGTd LCAQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; t=1774601869; x=1775206669; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pk6EZMhmgrzb7jNWyt/7nAovGzWtOSfwxA/NH1FTYXY=; b=BC52B9U4IApt3rJFSOu4Zg8rxNIic09i4ZVtvdVElMrFKde49lzgePi6zHCS13uSU+ ILtxCx+Gf6mOeb0ojWoZvSgXeNjdIkhpNVUzJIYN/u3ERAPdExVWUTRt+0727fnC8Q7v hplADL8+tpHJS1VzzoA1XntUKkXmt2AsWI3oU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774601869; x=1775206669; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pk6EZMhmgrzb7jNWyt/7nAovGzWtOSfwxA/NH1FTYXY=; b=WR/syHBxO3yOUHswwZf9/dF1zrRNMazWQM/zb4fQXpi276Lo0oLu9Rj9uxxGrNWRm0 WDcnXzxLH3iLUYDALmqUoOynTYLUZw8shO00YekSM5y3GgekYoZ6tdz974wTc7+C+YgK XPy9G/DO9jmTFi5hY0vmGHl+jNkhSzm85JSjjFLFYyg9/zGbxerOi7LKCRpNJB8XIuym dFmfdMVJp9dYv8R+sawXgf00mdXcHnJuAsVMG0+ZGEdfc995nRYyGiSEwcmMf12kYl+t TCGUciqzUAlFe50I3ywufHHICfCCmZ6D7n3nRcaYToWKwk5ZEkO21a9NjFTsBDtvm1Bu i6ug== X-Forwarded-Encrypted: i=1; AJvYcCVQJBjD+iPV1D2/jzAHpqJE4d9AL/XGCjMGmpO5hD0w2H94+uj8UCG1qJK1G9J6PEKlcURFYF27wk01@lists.postgresql.org X-Gm-Message-State: AOJu0Yweqe6HcwcAhz/tq7h1innUYVYacvwnit/iOrxvLJdko9b3FOxv JjjyNPINfkHju+OGMgboM0tksHmRcK30gBJ/fEl/1kfcduzXLMb2eABvMom9kqNZ5rHpM0O0mmJ G2oyxTjr4Kdlg06Eff4lh2FEjyJq1KZSWIo86h63f/ffNdE8RRTTOI8TuxQ== X-Gm-Gg: ATEYQzxUSrl4jIwCcp2Fhc8JeBhNgopylJUayT/hILhZpLMzOuERDFcCqfY+vVEGW0R M9eApk+fbisgYr5s4ix62T14wz4FpG7Ep7dvPUDK96ofvm8nP7RklMoyTP72/zfKxkyqYtFNHKR SN5P3f5lI7+na23KmmZhJfDvTZShj/yM+W2KGN87V4QbvZUUtQSaWfIZUbUAAfkWvQpofDPw2OB wjAgApDJdLKpjIY6P6tHgs+B6lb6O1MZyepgatJtWbG+o0381Rd9wbOzmPBomGKAsx6utZmJfjl sX0VF6/5 X-Received: by 2002:a17:902:ea05:b0:2b0:af2f:b26a with SMTP id d9443c01a7336-2b0cdd13422mr20174995ad.48.1774601869025; Fri, 27 Mar 2026 01:57:49 -0700 (PDT) MIME-Version: 1.0 References: <91A12197-68B4-4C9E-8F5B-DB26D9FA30C5@yesql.se> In-Reply-To: <91A12197-68B4-4C9E-8F5B-DB26D9FA30C5@yesql.se> From: Gaurav Singh Date: Fri, 27 Mar 2026 14:27:37 +0530 X-Gm-Features: AQROBzA1JDvmS8uerrL4Jf9oLSstU7AofWD5xVtmIkMMduy-Bns5MKwx6r8F9us Message-ID: Subject: Re: Memory leak in pg_stat_statements when qtext file contains invalid encoding To: daniel@yesql.se Cc: Lukas Fittl , pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000056d6a064dfdb206" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000056d6a064dfdb206 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > We could also use palloc_extended() with MCXT_ALLOC_NO_OOM to avoid erroring > out on OOM and be able to return NULL? Oh, it seems palloc_extended() would be a better fix. -- Gaurav On Fri, Mar 27, 2026 at 2:21=E2=80=AFPM Daniel Gustafsson = wrote: > > On 27 Mar 2026, at 09:21, Lukas Fittl wrote: > > > But I think you're correct about qbuffer - because that buffer is > > using malloc (not palloc), its not part of any memory context, and so > > it will happily leak on abort. > > > > It appears our use of malloc in pg_stat_statements is so that we can > > fail on OOM and return NULL without a jump. I think that makes sense > > for when a GC cycle was triggered during regular query execution > > (since we don't want to error the original query), but it seems like > > just bubbling up the OOM if needed when querying the > > pg_stat_statements function seems fine. > > We could also use palloc_extended() with MCXT_ALLOC_NO_OOM to avoid > erroring > out on OOM and be able to return NULL? > > -- > Daniel Gustafsson > > --000000000000056d6a064dfdb206 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> We could also use palloc_extended() with MCXT_ALLOC_N= O_OOM to avoid erroring
> out on OOM and be able to return NULL?
<= br>Oh, it seems palloc_extended() would be a better fix.


--
= Gaurav


On Fri, Mar 27, 2026 at 2:21=E2= =80=AFPM Daniel Gustafsson <daniel@ye= sql.se> wrote:
> On 27 Mar 2026, at 09:21, Lukas Fittl <lukas@fittl.com> wrote:

> But I think you're correct about qbuffer - because that buffer is<= br> > using malloc (not palloc), its not part of any memory context, and so<= br> > it will happily leak on abort.
>
> It appears our use of malloc in pg_stat_statements is so that we can > fail on OOM and return NULL without a jump. I think that makes sense > for when a GC cycle was triggered during regular query execution
> (since we don't want to error the original query), but it seems li= ke
> just bubbling up the OOM if needed when querying the
> pg_stat_statements function seems fine.

We could also use palloc_extended() with MCXT_ALLOC_NO_OOM to avoid errorin= g
out on OOM and be able to return NULL?

--
Daniel Gustafsson

--000000000000056d6a064dfdb206--