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.94.2) (envelope-from ) id 1tiFsy-00DWdz-S0 for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Feb 2025 16:46:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tiFsw-00Ar6Y-TH for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Feb 2025 16:46: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.94.2) (envelope-from ) id 1tiFsw-00Ar6Q-Fk for pgsql-hackers@lists.postgresql.org; Wed, 12 Feb 2025 16:46:51 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tiFsv-000RX9-0w for pgsql-hackers@postgresql.org; Wed, 12 Feb 2025 16:46:50 +0000 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-21f3c119fe6so160877755ad.0 for ; Wed, 12 Feb 2025 08:46:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739378808; x=1739983608; darn=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=AZt5t7vj6NcoTXHec8pS3hzQkslVmppaYiZ0N0GMCMg=; b=P1JX8tP6nfgMyDdpOmJtffcvM9MG/qduV1O6i35raC0zV4ENrbZwKRAcpjj9ZGzDV2 87CwWxoDCm4mkcIpZxxG7knAg6DGfbIsTdjqwcp7Czm1sPGFk4auPO8Qr9a8ygQcFpyX 5L8Pt+NHnUyMBv6d4BX2NdH50Xr6jYUmDy/JqYcddYg3EP1YdvUOS2N5MehVPqfjwEm8 Dr4Zvvntalsoafv1mB0xZStMlvZl7ZX+4XxdEFwXqoVnxD5SnJbaVrHVTCvwMAzpAgZr vX1rT8ZmaOp4Kl4OI7gEIbryBrIxe+0IMuffs5KXO9ZOhyV5qwhLNgQVzn4EYqhXdCri 1o5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739378808; x=1739983608; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AZt5t7vj6NcoTXHec8pS3hzQkslVmppaYiZ0N0GMCMg=; b=Q46Y0rm84RdUlSfipHAdMk7afhlV2g9qjzVd5annMDTNfp7m4I1nvD0bbRQW/x7gIG qDsd29VKirn3V7PODqF2qT+/gTIJnsnil7r9FbWDcxHMRhPodQXboFnWA/TndhDr8Vro DvY95v3gJMT3gQk/2M/8hjI3DZOPdBjZr7wumN07SBq8oer2niICstM1wdyAsUCYpN+4 COpTIMv3RfL32a/pOxsMuVd15re0grL3MU/hA5y066Z6jJO3j97OqOlGIbsfJsibukmt kpK4bO8c9bjKRPr3MqYUY/6iUEKyaoLUMlEEbejKtuSM8lwBtI8u8axhiyBRsgJIE0p1 AS3Q== X-Forwarded-Encrypted: i=1; AJvYcCXjgCxquaxusNtvecQdyshq8hFxZbim9uVj9fu96AxxdRUVZRsOaBZqQJ3KVQke+7X1aXiUHa/FMt7x3wED@postgresql.org X-Gm-Message-State: AOJu0YwrpMCMeOcmiWhyEq+PvU575im5V3xPpC8W6+0f7ErWpzGOjCTI j7rFRP8VshAQt+GviKAvPSODcMUrE/k18+mpltPxbys+il0HdByvE2mpL1sdfdVsCDkW58qSixr SMKLTospIIlsi+oBfcLS+/gxU01I= X-Gm-Gg: ASbGncuiAYDQUv3k1EkyNEV8LO6DPF9NaIiiq1wWykf13m0J7LcFCUMEembTKKTB+cP LFvw9mWZHzGyS5OKapj4EIysppWRInrgFKPoUd1+WZtYDjMYX1vjFQ8yIyk6cfufdfpYMKBY/ X-Google-Smtp-Source: AGHT+IEh/kQnR/qDN6hrtihCKyerYhFX7QtoKoxI3qcFDnulL+DVxqKsrqq9zAhv/1AzaSjXBSXE+bNBWKOqebqY3OE= X-Received: by 2002:a17:902:f791:b0:21a:87d1:168a with SMTP id d9443c01a7336-220bbcc13c1mr62412405ad.41.1739378808180; Wed, 12 Feb 2025 08:46:48 -0800 (PST) MIME-Version: 1.0 References: <68d6d810-4ef1-4f62-b47f-89b21501249b@app.fastmail.com> <3337507.1739376124@sss.pgh.pa.us> In-Reply-To: <3337507.1739376124@sss.pgh.pa.us> From: Ranier Vilela Date: Wed, 12 Feb 2025 13:46:38 -0300 X-Gm-Features: AWEUYZnz4Cqf1S8Vh0nGdo36VGdxH83wsoQKP1DiiXqBcl7q6hPbEgQQw8A1bFA Message-ID: Subject: Re: Small memory fixes for pg_createsubcriber To: Tom Lane Cc: Andres Freund , Euler Taveira , pgsql-hackers Content-Type: multipart/mixed; boundary="000000000000fde916062df4afd5" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000fde916062df4afd5 Content-Type: multipart/alternative; boundary="000000000000fde915062df4afd3" --000000000000fde915062df4afd3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi. Em qua., 12 de fev. de 2025 =C3=A0s 13:02, Tom Lane esc= reveu: > Andres Freund writes: > > On 2025-02-11 13:32:32 -0300, Euler Taveira wrote: > >> There is no bug. They are the same behind the scenes. > > > That *is* a bug. On windows the allocator that a shared library (i.e. > libpq) > > uses, may *not* be the same as the one that an executable > > (i.e. pg_createsubscriber). It's not correct to free memory allocated > in a > > shared library just with free, it has to go through the library's free. > > Indeed. This is particularly pernicious because it will work even on > Windows under common scenarios (which no doubt explains the lack of > field reports). From the last time we discussed this [1]: > > It seems to work fine as long as a debug-readline is paired with a > debug-psql or a release-readline is paired with a release-psql. > > I wish we had some way to detect misuses automatically ... > Unfortunately, for now, there is only manual search. In fact, after your post, I did a new search and found two other occurrences. (src/bin/pg_amcheck/pg_amcheck.c) One fixed in the patch attached. Another *dat->amcheck_schema* is it not worth the effort, since the memory is not released at any point? Trivial patch attached. best regards, Ranier Vilela --000000000000fde915062df4afd3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi.

Em qua., 12 de f= ev. de 2025 =C3=A0s 13:02, Tom Lane <tgl@sss.pgh.pa.us> escreveu:
Andres Freund <andres@anarazel.de> writes:
> On 2025-02-11 13:32:32 -0300, Euler Taveira wrote:
>> There is no bug. They are the same behind the scenes.

> That *is* a bug. On windows the allocator that a shared library (i.e. = libpq)
> uses, may *not* be the same as the one that an executable
> (i.e. pg_createsubscriber).=C2=A0 It's not correct to free memory = allocated in a
> shared library just with free, it has to go through the library's = free.

Indeed.=C2=A0 This is particularly pernicious because it will work even on<= br> Windows under common scenarios (which no doubt explains the lack of
field reports).=C2=A0 From the last time we discussed this [1]:

=C2=A0 =C2=A0 It seems to work fine as long as a debug-readline is paired w= ith a
=C2=A0 =C2=A0 debug-psql or a release-readline is paired with a release-psq= l.

I wish we had some way to detect misuses automatically ...
=
Unfortunately, for now, there is only manual search.
=C2=A0<= /div>
In fact, after your post, I did a new search and found two other = occurrences.
(src/bin/pg_amcheck/pg_amcheck.c)

One fixed in the patch attached.
Another *dat->amcheck_= schema* is it not worth the effort,=C2=A0
since the memory is not= released at any point?

Trivial patch attached.

best regards,
Ranier Vilela
--000000000000fde915062df4afd3-- --000000000000fde916062df4afd5 Content-Type: application/octet-stream; name="fix-api-misuse-pg_amcheck.patch" Content-Disposition: attachment; filename="fix-api-misuse-pg_amcheck.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_m7257uzw0 ZGlmZiAtLWdpdCBhL3NyYy9iaW4vcGdfYW1jaGVjay9wZ19hbWNoZWNrLmMgYi9zcmMvYmluL3Bn X2FtY2hlY2svcGdfYW1jaGVjay5jCmluZGV4IGM1ZWMyNWJlMjIuLmRkYThiMWI4YWQgMTAwNjQ0 Ci0tLSBhL3NyYy9iaW4vcGdfYW1jaGVjay9wZ19hbWNoZWNrLmMKKysrIGIvc3JjL2Jpbi9wZ19h bWNoZWNrL3BnX2FtY2hlY2suYwpAQCAtNTYwLDcgKzU2MCw3IEBAIG1haW4oaW50IGFyZ2MsIGNo YXIgKmFyZ3ZbXSkKIAogCQkJZXhlY3V0ZUNvbW1hbmQoY29ubiwgaW5zdGFsbF9zcWwsIG9wdHMu ZWNobyk7CiAJCQlwZnJlZShpbnN0YWxsX3NxbCk7Ci0JCQlwZnJlZShzY2hlbWEpOworCQkJUFFm cmVlbWVtKHNjaGVtYSk7CiAJCX0KIAogCQkvKgo= --000000000000fde916062df4afd5--