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 1w9s0k-001qEf-2q for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 22:01:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9s0j-00CN9W-0x for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 22:01:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w9s0j-00CN9N-03 for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2026 22:01:33 +0000 Received: from mail-qv1-xf32.google.com ([2607:f8b0:4864:20::f32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w9s0g-00000000yRr-17Lm for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2026 22:01:32 +0000 Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-8a068db9989so52420136d6.0 for ; Mon, 06 Apr 2026 15:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775512888; cv=none; d=google.com; s=arc-20240605; b=ed33Ygtd3HtHDulzVuhTfA/wkq3Y4POMdZlKasuY1STRVC+niRm2I/Ow2PY1ApJL+p DagxZpcOJ7+I6nEgda2bddAHZn/smuqTF1+406KEYHCJIr/GgiS3R3crXgmxM9pfFOsz j2FzbtXIaUS0ATeO9OZxQjulZo0Mofyv5vquCtvoivOi2+GbcjBPu3mHeKXWttE4L8MQ 4N3TQg43s1M7bEA7qc7CDy6XFyjcFbTU/AumpGuuU3nNslMEGkDTx/NokAn05OqUXPFr zCkH9fWplU1fdRgfkuxXruUgaSkzthOnQdXYNiNwcByACEvDAjKcGGWASKAPYzc0USfO gVVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=2dvMZsDcHRzjhLYvi4s4cyJjanV0gkozFSVUrnfSLmU=; fh=4Mvn3FOaPd40RHHQwHen3D/75r10Qd/WuZAgJHFEA3E=; b=OvPXZ5OfwhaSoRTwnfhfNXhm3afEi6WCBsJgz2bjbgG7zprxX2tIjWlwHDxhdSS4Ga y7JrtXMuP8oKSqTXjKvZucH3i/CydelgumoF08z5Kx0Jpkqo8cPzdg4HmKXNnwbX4VN/ Yme5ia0W+AOhWm3jsHi2ox1AAc1JdcmMtt6yTf/MfovWcTipN1IXSf7zBJNizQXHMFxT 2wtrZmto6rhihfd1Zr+olHXGdRcDmSyF4slF0XIQmX3+k9CziUPGSxprztAfaUcWLoqr ZrFocfepbNkrootKGUnL5Re+Hn52vb2EgDgAUV7+7cVDYZlUfvFZTju32eEtOf8aoCW7 duKQ==; 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=enterprisedb.com; s=google; t=1775512888; x=1776117688; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=2dvMZsDcHRzjhLYvi4s4cyJjanV0gkozFSVUrnfSLmU=; b=VMsKgnaDihV6Ow7MZ/ct4w4prMaET6D0abIYu2WsrBeZlvSoLZQ22oDoV6MoVPDRD1 92nANgJLYp2ffEfyK/57aZ5NYNa6CiofDS+AWcA/c6H3F3c7ZfT5youlNeul6Ksg2yOJ Dgcl1loVqb4QpfvVRBN/BDrCWngXnTFHQv/rWXwrBi5WejiOMQglEHWkL1E2J5XRJ/Oa HDBvSUEJxk7GtkUo4SBQodTmhGOGHbBawH6r7hr0Z8I1TBg6/XNQs4fsOFABO3uGoEpK qGB3H17+mDxLpFaEIHzVXMLfHmQNKKpjLJqYFqjc02TtN8pZP6Shmh9U+YcJ064m20B+ XQUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775512888; x=1776117688; h=content-transfer-encoding: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=2dvMZsDcHRzjhLYvi4s4cyJjanV0gkozFSVUrnfSLmU=; b=Z3wB1EjXdRSRsto3e7tovMZR+gWkpAQIeGG0+2MGN/UNMTMIiAKuXzE2PGOGPcMb/t RKZRrDCXfmLdiCpkmm4HVUpJQCYpEbI1ZNCGyPuXsr9g2Eol+3GTvTQQJv/OWD6WZL4C IpVMINLcEhQ6tecabcmEXDiNMXBlfIRxcPlIGUgqMCri5uO0yzzQo6Y09LV6074VD103 asQrj2jBOlnSoVbGJjfneYweWrvwDStsmzRzPzo4NudaaBbnUA+OrZT1Si/DatsdLGxS qXqmopKD8c0uo1oZQkj1vxkJDT5LebFFxOv1btmEiH0o24fzqZ0JTJ6hYzsxZPshpZGn /gow== X-Forwarded-Encrypted: i=1; AJvYcCXOozdV5b+ggU6Sz5KCoIdT6N6/YCEBySgfty2JsldrjdFxEM/fO/ReP5IklCQhMkPc9aZM5fkiSXn7poeW@lists.postgresql.org X-Gm-Message-State: AOJu0YwNtqbwmc3FA3AfZ3JM7Rdwx5tZjTaH6IyOe2WB/Py9uVBuvc6q lDzhZAlGsFLBJpL3FRziWMZMIvdvMsAkC4XBMt2dohkEHNPj+1xecW2y15Q2U/bM3gdm8gK1ALl Zma3Y6d03N8e39F0pk5TKDSCP4mraHoLEu8T23rib X-Gm-Gg: AeBDieu/PzLCtaW+XI2DB+gCoKiSV36S5dC9jZXi0ZMkcfYHO3r48T360nc1qfQYwQy OZdVhN6WEGR6Dmy1+xmQKuWy0A3V/iCS67nZ+DLTgKAOp5vd9A8Er9WsgV9Fr2NOOjVRGn/kC7M NY2SqHpeaIpd6/oxqoR31SZ15601z+3zbpF/1Y1o7kJT4sszcdwTT+SZDdmmfag6f5VjsGTOKTb nUP2OI7UCNrLRpp1N+VwW5vLOaFHmonIlCmRZeHVL2gePFKY9YGxjjxE3TnQvepH4LiZbSOnV6b lABZoI7sjQ== X-Received: by 2002:a05:6214:c85:b0:8a4:b884:886f with SMTP id 6a1803df08f44-8a703939adamr199870616d6.9.1775512885586; Mon, 06 Apr 2026 15:01:25 -0700 (PDT) MIME-Version: 1.0 References: <0b32e30f2fb94ae3b7f4ee15bbb072c0@rutoken.ru> <107eb23a-8ebb-42bc-99c0-ca551733e94e@proxel.se> In-Reply-To: From: Jacob Champion Date: Mon, 6 Apr 2026 15:01:14 -0700 X-Gm-Features: AQROBzAMISZPhPfFIJRZ66P-7fx9RG4dTilZNTaX0nVUERM-OgrWU51c61tW5i8 Message-ID: Subject: Re: DEREF_AFTER_NULL: src/common/jsonapi.c:2529 To: Andres Freund Cc: Andreas Karlsson , =?UTF-8?B?0JPQsNC70LrQuNC9INCh0LXRgNCz0LXQuQ==?= , "pgsql-hackers@lists.postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Apr 6, 2026 at 2:40=E2=80=AFPM Andres Freund w= rote: > > Maybe I didn't parse this question correctly, but I don't want to > > avoid freeing NULLs. It's entirely reasonable and normal to write code > > that frees NULLs. > > I think it's a bad idea ever call free(), realloc() etc with a NULL. It'= s imo > quite the code smell indicating that code lost of track of whether someth= ing > was allocated or not. I could not disagree more strongly: - the alternative for many developers in practice is going to be a unilateral `if (ptr) free(ptr);` anyway, losing any potential "benefit", and - I'm not even convinced that "lose track of whether something was allocated" is a thing. If it was NULL, it was not allocated. If it is not NULL, it is either allocated, or you're about to double-free something, which has nothing to do with free(NULL). What's to "lose track" of? > The whole point of having pfree() in FE code is to make it possible to wr= ite > common code that doesn't need ifdef around every allocation. Which didn't work out for us, in my humble opinion, as soon as libpq entered the equation. We don't have to name the abstraction layer the same thing as only one of the branches of the abstraction. > > Or else make pfree() behave like free() [2] so that we don't > > have to have that particular papercut at all anymore? > > -many > > It's also not a path I want to add any unnecessary instructions to. Okay, but I'd be curious to know how widespread this position is. > > It still doesn't help the OOM abstraction leak between libpq and the > > backend, as far as I can tell. > > If the code were to use a JsonLexContext field to decide whether to pass > MCXT_ALLOC_NO_OOM to the allocation functions etc it'd at least would mak= e the > code more similar between FE/BE due to both having to deal with NULLs. I'm talking about libpq here; we don't link fe_memutils.c at all. --Jacob