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 1u8WA4-00652s-CU for pgsql-general@arkaria.postgresql.org; Sat, 26 Apr 2025 03:25:04 +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 1u8WA2-000D1b-1K for pgsql-general@arkaria.postgresql.org; Sat, 26 Apr 2025 03:25:02 +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 1u8WA1-000D1S-LN for pgsql-general@lists.postgresql.org; Sat, 26 Apr 2025 03:25:02 +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 1u8WA0-001zmZ-0a for pgsql-general@lists.postgresql.org; Sat, 26 Apr 2025 03:25:01 +0000 Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-7053f85f059so28737127b3.2 for ; Fri, 25 Apr 2025 20:25:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745637900; x=1746242700; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=lPmflmZTb1MGcArZHtsCn8l/NdLJD2c/2AM78oCRwN0=; b=R7tv3Rpffj/vuFhbcx0D98BA/naH7kBFbzeOE23n7O1FfNVoc7ifWwj4UTYGu4uy7h o48PFn3tPIbB5sHR4RbAQhIHIsfiMXMOjZ48da12XDG2P9yghau8dbiMg8D+of2cf8mX EuLR9tbV+R23Vh9NbpzQc72kTZfpbILMaNM6Ach2l1zQWRqGqI3wMQXUXFOsHl9SAFZH dPne+3t7beieqKH9d27aJPkZFZzLhc3cIOGVbupsJfdpK4CiBa1UCILPwSjvykVholcZ TAv29KdKnbHcnKAghz7IX703I2p4xMc92thcZbbRYxgDeIAPCy+DO2npBwHyg2UW0xUy mlpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745637900; x=1746242700; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lPmflmZTb1MGcArZHtsCn8l/NdLJD2c/2AM78oCRwN0=; b=MrZ7BKSkAiGEQsjGTI3KE0bgAspwTASjC73akKImThjPbt3EHu6X03xBwRVBNdPrJL mtu5eCabytAjvvGzOZmhpipw12QJdjbDRKk2XbbkAK/Ze/eg04LoiepDjszF8AFZhrFM tMHQ3dTG9AmfpCT015sh+HDPwYw5AEK+bYDgB39IPXqaZmmHAwhkhNOjVAQ/JQR4Hnze fwa9j7Pga3i1rFhl9ApgQUjNuDcPlX/WQ+wzSAIjn+pZ1F8Vh9gEMPHDWWnINP6zGJ9V zDdilrPM27V+qR0motISFgRBCCawM3i+rB2dFgV8ZRc1kZgQGzJZ99h5ZXNdr7HlHSao 2UaQ== X-Gm-Message-State: AOJu0YxJdB1UMEtlO3MmhM+xpaRbRtIQc192ADdVgLoejeDw6L3F2b9u Z/qXA/uIlTwTkT7qmLLzYw1SFDwuJOxOX6oIXHrq+TsMpeJYOkoDl0156+pyjCuCe5uT6HS6i07 hzz0LU1h4sjabkWiHrnR3X5RYXXo9hLJI9Ys= X-Gm-Gg: ASbGncsN2BU/6iBwZa+AnbLOWcWc6Zhs/R11BCHV9/FH7xEKPRBKh3B1lYGC9euHTh8 zbivSrZpLbhUpNQ7MSAd88HEbyQSLfr7qEXWigSBTTywSZrzW5/pADFhFxV9cYh/1agEAf9izHo oa8RP4JdCrhjYt2owpwVyLezLOZ77SQu4kqo48kTbiUR8239CIBtdBQ8c= X-Google-Smtp-Source: AGHT+IHlHQ+3DSJ7fPSJXV3+75lqhoW6d+7Pb9pB1o/uBIV2vuSKoo8wvZkABgkebwL/alzDeFqkQ39L8B1S1gBMGZ8= X-Received: by 2002:a05:690c:3708:b0:702:5926:8609 with SMTP id 00721157ae682-708540fa0e6mr67671987b3.12.1745637899782; Fri, 25 Apr 2025 20:24:59 -0700 (PDT) MIME-Version: 1.0 From: Igor Korot Date: Fri, 25 Apr 2025 22:24:49 -0500 X-Gm-Features: ATxdqUHpTdBMkHB8sS6muRUQplnpYpOHD9VjC4RBtpoUJD42cMLIhEBEusZTpw8 Message-ID: Subject: How to properly fix memory leak To: "pgsql-generallists.postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, ALL, [code] auto res = PQexec( m_db, m_pimpl->m_myconv.to_bytes( query.c_str() ).c_str() ); /* ask for binary results */ if( PQresultStatus( res ) != PGRES_TUPLES_OK ) { auto err = m_pimpl->m_myconv.from_bytes( PQerrorMessage( m_db ) ); errorMsg.push_back( L"Update validation table: " + err ); result = 1; } else { for( int i = 0; i < PQntuples( res ); i++ ) { auto temp1 = 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. Should I call PQclear() on every iteration of the loop? And I hope I handle the error cae properly... Thank you