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 1u8Xrj-006smg-2P for pgsql-general@arkaria.postgresql.org; Sat, 26 Apr 2025 05:14:15 +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 1u8Xqj-0011No-4y for pgsql-general@arkaria.postgresql.org; Sat, 26 Apr 2025 05:13:13 +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 1u8Xqi-0011Ne-Oy for pgsql-general@lists.postgresql.org; Sat, 26 Apr 2025 05:13:13 +0000 Received: from mail-yw1-x1132.google.com ([2607:f8b0:4864:20::1132]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u8Xqh-0020au-1Z for pgsql-general@lists.postgresql.org; Sat, 26 Apr 2025 05:13:12 +0000 Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-70814384238so27531197b3.0 for ; Fri, 25 Apr 2025 22:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745644391; x=1746249191; 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=IbtTtNbyCIY0yx+k67XaAiZw73gbrOc041nZVkSr3Qc=; b=YgkvIcgCJrbLa7fppSLhUGkaPeLUXNHGVSGGfVabXvVfDVDYr8pXU5KXCig8iHCRcl k64euemytVBmkmjoczKLaZPxseJAWbr9rxowvh9FqS8njJqFwoPhk5k8AVpdbXL497M/ 1gerNp3r/iorX1PArMg7pfWBJLWJtnUwBcdDeoWu+UQPs4b/mtFYIu1d/pPAOA8CHIIW 8vrFweVG0XirAKbdg+iku9tTeTc4ZOlasUvwejzS3b7XJ6d6Lw/PJtKtO7uNMemEeLe1 vPqAX/8/K0qsBSX5LN6HKfvPyJM78OpprJBT/xnQ8AtFrNRb4e+N88uIzeaCYv/cgCtz Odgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745644391; x=1746249191; h=content-transfer-encoding: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=IbtTtNbyCIY0yx+k67XaAiZw73gbrOc041nZVkSr3Qc=; b=vGYNdN28L6TnW4v8HyuZurkzl5rB7Z8ynFLCA9ai/vW+tpnkm+4Ybhb2SGRsNfK4Ad c8b48VrQsJhvNY8yO+HhEcTn5JgbLVOiNpRdkeDu5LpRlz/ZYA1ByAK0aC1kb7s9Qshh 9YReapLHO2I7oEPsxh5kd7h0sh61FhBcWz9jC+21ttTsq9ywWNPOJpP+P1Ou9uCaaZsF I81ZW8Lyfu00zKnY5R1oDr2pJBMlBOMi63EiaMWY7dOuWu3qfp1L1EN4QdjieIDswaxW 9VcTUjS0AcWGcbIpONvL1/421wEtboJSeHZVYz4Z9Bw3EqVwjfajqVZV+A6f4loqNOh2 Eh/g== X-Gm-Message-State: AOJu0YxMcffYXwaFxENHAcMSJbagvGegvUYTrQc6/9Z4EcdyxywIrqY+ g3TU0L+XZNUWX5+2lhEpQzaEBjAVxNAUrZis5I/iWgh4ct6+2H7H8fpBbV8+G/nhDnQpSisKWJM ozDwN/T3cVdgc9EROTfDnEt02rws= X-Gm-Gg: ASbGncv8FCb7rMFLm4IBowDey0Xtab7ok6WZdIFE1NhDpR3VJx0B2pBQiopkIU8ZA7M aVoLeh6TRNqQMfrn0QYqFtK/231CFnJOribWrw5BhnnKyFsn2r25v3formMIEel4gC2owGm62LI hXQPQQcuigNOfXiAiggY5yS75o0smPhjxzMoNZlkn1qv81swtqjeQ81Co= X-Google-Smtp-Source: AGHT+IGgqa7Gi9lHYQUYzYFo1CulZvU5bg4sAygIXZSqEVUVz37H66tgTXKvupwAIOPkDtNOvOMWeaHwmRMwayga/PM= X-Received: by 2002:a05:690c:9a86:b0:708:2d8d:11de with SMTP id 00721157ae682-708540e72cdmr75193637b3.16.1745644390801; Fri, 25 Apr 2025 22:13:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Igor Korot Date: Sat, 26 Apr 2025 00:12:59 -0500 X-Gm-Features: ATxdqUFhUeRAkWwdTZzBazXEqSPP5yQ7O4IJ9NRv0gM_PKcAzm_ymkV9kYEP49A Message-ID: Subject: Re: How to properly fix memory leak To: "David G. Johnston" Cc: "pgsql-generallists.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 Hi, David, On Fri, Apr 25, 2025 at 11:55=E2=80=AFPM David G. Johnston wrote: > > On Friday, April 25, 2025, Igor Korot wrote: >> >> >> And the error case was handled correctly, right? > > > Seems like answering that requires knowing what the query is or can be. = I also have no idea what idiomatic code looks like. Though, I=E2=80=99d pr= obably use PQresultErrorMessage and check affirmatively for the tuples and = error cases and have a final else should the status be something unexpected= . Understood. Below is the full function: [code] int PostgresDatabase::PopulateTablespaces(std::vector &errorM= sg) { int result =3D 0; std::wstring errorMessage; std::wstring query =3D L"SELECT * FROM pg_tablespace;"; auto res =3D PQexec( m_db, m_pimpl->m_myconv.to_bytes( query.c_str() ).c_str() ); /* ask for binary results */ if( PQresultStatus( res ) !=3D PGRES_TUPLES_OK ) { auto err =3D m_pimpl->m_myconv.from_bytes( PQerrorMessage( m_db ) )= ; errorMsg.push_back( L"Update validation table: " + err ); result =3D 1; } else { for( int i =3D 0; i < PQntuples( res ); i++ ) { auto temp1 =3D m_pimpl->m_myconv.from_bytes( PQgetvalue( res, i, 1 ) ); m_tablespaces.push_back( temp1 ); } } PQclear( res ); return result; } [/code] Thank you. > > David J. >