Re: Help needed for the resolution of memory leak - Mailing list pgsql-general

From Sasmit Utkarsh
Subject Re: Help needed for the resolution of memory leak
Date
Msg-id CAM-5MT08CpF=TsUY0kQkucqNusFLxJgUPPvdUwvU70HC71DsNA@mail.gmail.com
Whole thread Raw
In response to Re: Help needed for the resolution of memory leak  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-general
ok Thanks Merlin, I will go through the above specified doc and get back in case of further questions

Regards,
Sasmit Utkarsh
+91-7674022625


On Thu, Jan 18, 2024 at 6:36 AM Merlin Moncure <mmoncure@gmail.com> wrote:
On Wed, Jan 17, 2024 at 1:14 PM Sasmit Utkarsh <utkarshsasmit@gmail.com> wrote:
Hi Merlin et al.

Below are some couple of observations attached as an "overview_of_code" and other attachments "function_def_other_details" and leak sanitizer report. Please assist with some clarifications given in overview_of_code with (***). Let me know if you need any more information

***How do we handle for the case clearing when PGresult object is assigned a pointer to the data of the specified field within the existing PGresult object?
i.e when SQL_get_tpf_rw() actually completes in each iteration? 


It is your responsibility to close PGResult and PGConn objects.  Each one created must be cleaned up.  This is basic libpq usage.  I suggest studying the documentation.  


Start here: https://www.postgresql.org/docs/current/libpq-exec.html 
Also Study here: https://www.postgresql.org/docs/current/libpq-example.html

You should not reuse a pointer unless you have cleared the object first.

****Is the leak reported due to improper handling of the above case ? or is it due to some other flow
Your leaks look mostly due to not cleaning PGResult.  However, the real issue here is you need to learn basic libpq usage a little better...try writing a smaller program and see when it starts to complain about leaks.

merlin

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Moving to Postgresql database
Next
From: "Rossana Ocampos"
Date:
Subject: AW: Nested-Internal Functions