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 1u8u5o-00DJfk-Qg for pgsql-general@arkaria.postgresql.org; Sun, 27 Apr 2025 04:58:17 +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 1u8u5l-008dMN-3Z for pgsql-general@arkaria.postgresql.org; Sun, 27 Apr 2025 04:58: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 1u8u5k-008dMF-Mq for pgsql-general@lists.postgresql.org; Sun, 27 Apr 2025 04:58:13 +0000 Received: from mail-yw1-x1133.google.com ([2607:f8b0:4864:20::1133]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u8u5j-002AMd-1F for pgsql-general@lists.postgresql.org; Sun, 27 Apr 2025 04:58:12 +0000 Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-6fda22908d9so27965557b3.1 for ; Sat, 26 Apr 2025 21:58:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745729891; x=1746334691; 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=zesbLAL93lJOrjX/cwWwQKRIZtTgQ1U62OeeZeYLPP0=; b=h8XW1lSzDefZ47hPe/6C4wNu/DdcjM6bfH7iEcsuywjTDxP31eB5Nf4iXkW1Er70x+ TnEIUK2yzpNVjyICFbxH9BJLdqIN0ky/4E1YaWQq/bEZ51n/zp0RAAjlQRGS7t//msfL L9xc8Cd2TliT6VNYL2vCXL96mFfgJoVIxwpK5+Wlkxu2K3Bv8rf0Pf99XHNbNYoSt2zB Upm9HHieKOnoF7H/KeqryqdwgzKrgwjj6mbYzg+r2esvR+IVdA6qBA0aY9keUBAEJfxW HEOg2vNN8Jl9OAw2sPNGk+SpBELPXszdYybmoLXmA8q4QdN8koiH8orSxiqeiTtcr8hM hZGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745729891; x=1746334691; 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=zesbLAL93lJOrjX/cwWwQKRIZtTgQ1U62OeeZeYLPP0=; b=pTtqFsiYMEYk/eXzo4idq7v+3NYv0FZoAJWpVUcwxDmLYYmFF2e/43t63fIQnpWhq3 I4/vIZbF9YjPEl2pktjXdiHRSkUyFvUziEaxK8uAvEBSpuI3PQJrRzeR/fDGTAI8tzdi vh36y9NxQu9S8VzllOkV7fTcx46XaDwezDQjh5+Ok8slsKwEeVEToG/mbDqHvKFYTAl2 COliNEgDd60H6fEbMuPs0x2c3AkSHoi426FvSldgL8rHHpA2k+j2s88KVAteHeFNWrgd fOKUqunmz6JKN0CKOufMnC94ngoJsFGjYlpAtv4VO246M24s8qPES8MBIVSmgsBL3s3v WEsA== X-Gm-Message-State: AOJu0Yy0HbWKnT9scoQ1lnHB578n3J4OBy3cTuYC2zNArjgqnTf2Fvxx otwjh1VxKxlw3cLTscpDbSannb6G1soWE/zVGVoC7+cRhEP0pTMOvRx0sqv9MSyXgg2C04sFb3F tj4N/9sd1gKy/CpK7987a60QQGXk= X-Gm-Gg: ASbGnctlejZ8t4zTV4UOCKp0NyH5PPETgwn6zgH8TeAauVp5DVkdsX/4cIML/Qo+qfP g+NyfY9flGKl/Vp+pm6WDkGVSKPfAFf0XuxhRg0G6YFHQ+pV1gb1keU9aE+qNzE2srFXhiRZNkc oV8nJgzOw4vrX1QozeXvSy59xdkdQo0/idOLus4QRqZ9zwYdMDz/1KgfQwZx7i5CtPbg== X-Google-Smtp-Source: AGHT+IGTH80Y/+Md3GEgioCutk1XHIHR0ZwTfp+WU6zsnFLko2dC3mdfFooYdWCN4KMlIK0VU4ooY+HCfIGLObF3ulE= X-Received: by 2002:a05:690c:3:b0:700:b389:9246 with SMTP id 00721157ae682-708541f01e4mr101556737b3.38.1745729891036; Sat, 26 Apr 2025 21:58:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Igor Korot Date: Sat, 26 Apr 2025 23:58:00 -0500 X-Gm-Features: ATxdqUFHqOguE8CMYR_vCoAnHj8PCAR9hlsu1KMN4pljoyD7kF7CGwM7URbcGIU 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 David et al, 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. Looks like it is false positive. I ran the code under valgrind and there I didn't get such a leak. I did however get a different issues which I fixed. But even after moving the fixes ober to Windows and trying to run it - I still see that. For now I put this to bed as it is not an issue on Linux. 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. >