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 1u8Wyr-006Vqe-W9 for pgsql-general@arkaria.postgresql.org; Sat, 26 Apr 2025 04:17:34 +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 1u8Wyq-000cfQ-5J for pgsql-general@arkaria.postgresql.org; Sat, 26 Apr 2025 04:17:32 +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.94.2) (envelope-from ) id 1u8Wyp-000cfI-QK for pgsql-general@lists.postgresql.org; Sat, 26 Apr 2025 04:17:32 +0000 Received: from mail-yb1-xb2a.google.com ([2607:f8b0:4864:20::b2a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u8Wyn-0027RU-1X for pgsql-general@lists.postgresql.org; Sat, 26 Apr 2025 04:17:32 +0000 Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-e573136107bso2343201276.3 for ; Fri, 25 Apr 2025 21:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745641048; x=1746245848; 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=otrKz13nqnBBStMQ7jGPArAzBdSnCQ5lMCRXhcYKmhc=; b=jZk6gXS49bxI5qKXicHBlhYFej0dk/HoMA94a/Gt6SXssofM1DLX3cr7ffn7hOwGdG U+vYiRTnn0Wca96b94/mblkob7hthKmMfhqT9D2or7ri6PN96iPsY2qkQNAzr3WvuWBP XJFTl/kh0NdYUyjHslmtamdAkhOrdKEJ9/AIBaLKStPnRBkkrpJhGcmDUaTL3epCTzlS a46X2C6CiAzs1glFcpiFk3VADRjiGIgeVxEGiV3HSjjUDYy+6Zdu5NUGGZ79pVr5J3zj uZrS6DU6roU8Twn7Eb1EP50SSzKrDH38jXFUgMqHqCld9FSsfk7v+775Hj0EekoeDYDA oVdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745641048; x=1746245848; 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=otrKz13nqnBBStMQ7jGPArAzBdSnCQ5lMCRXhcYKmhc=; b=kjVrqBusKDbY1i8xYqfTvYXYJzndXVzVF4lV12BH20cYT5WQtl7FQC8SKyCLcUmDwo 7UUxO0aOMylLNC+UFVlsD0KvoMeqBY5ddRIuqWvtS5/p09JHv0nS8nIC48302HSZNjgM xYW5XQU3T8AA8IYC+JGq5FgWAZhsOSyowtxm0MsPu95t4UWwfNJE446p390L4jCQY2DW wglO4A/bNWOcYEZs/3OM4QIuwBgM3DHnzSuX4ZjZ7lLh0RxkpZg06sXsJIWuZH5Zwl5w u5a2WBfNSNsrWBs3doecdqlkJDnWjDJmANsX6ZS+MwASR/rSNWED+wgqxtF6WlNLGOqv 5pSw== X-Gm-Message-State: AOJu0YxOkYfLPrK7D0LuaExpd2Q1mp1v+UF/o2RY1aDmKjQL9YdQsPzV 53uRQHg7PkIvjBraDA6yryT+dcMjS2gS/mxB6swWypkRVeYmBhY7Pxqz/r0n8Yx3+FrB+X3MSNf ALXLSPfOS7Yuw2Rqn5moeO4VGqAg= X-Gm-Gg: ASbGnctNdXX2N4l43WEN9zikhESk4pyXvmRAKo0/WmpvxlJT/87TCs39hxZqMCc1uxo Ael6Sm9uedG49Wbv30aCjokrnzJOSucIP1p/Z50ZO9Ct2K7HUaFlAvxjH5G7xqAqEExGyKu6ijW eb41DMx73epwagYgoFOM50XyrRge7bjCjocIxH3VHxF3mgu/oH9a/jBlc= X-Google-Smtp-Source: AGHT+IHn5sO1ZaXC2m6CzGbJhuFUf0d+0f32B1DuhVyNSBl/LhCT0sdPX1aPfoVJ3FodVWB+UTjXMPZxfj+5v1cdGJk= X-Received: by 2002:a05:690c:4491:b0:706:b22a:e88a with SMTP id 00721157ae682-708542098eamr60840567b3.38.1745641048374; Fri, 25 Apr 2025 21:17:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Igor Korot Date: Fri, 25 Apr 2025 23:17:17 -0500 X-Gm-Features: ATxdqUGyMuADoLikdafAa6P5n0BAmBkk-6vEzLy4AWuSB35n_I5WccBQNoEe7rA 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 10:48=E2=80=AFPM David G. Johnston wrote: > > On Friday, April 25, 2025, Igor Korot wrote: >> >> >> 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 ); >> } // this line gives a leak according to VLD >> } >> PQclear( res ); >> return result; >> [/code] >> >> I ran this code on MSVC 2017 with VLD and according to the VLD report I= have >> a memory leak on the line indicated. > > > Seems like a false positive. And the error case was handled correctly, right? Thank you. > >> >> >> Should I call PQclear() on every iteration of the loop? > > > Would make processing more than a single row impossible if you throw away= the result after processing one row. > > David J. >