Re: memory leak in pgoutput - Mailing list pgsql-hackers

From by Yang
Subject Re: memory leak in pgoutput
Date
Msg-id DM3PR84MB3442C5736F1207066CFBCC88E3272@DM3PR84MB3442.NAMPRD84.PROD.OUTLOOK.COM
Whole thread Raw
In response to RE: memory leak in pgoutput  ("Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>)
List pgsql-hackers

> Here, after freeing the tupledesc, the ExecDropSingleTupleTableSlot will still

> access the freed tupledesc->tdrefcount which is an illegal memory access.

 

Yes, I overlooked that.

 

> I think we can do something like below instead:

>

> +                       TupleDesc       desc = entry->old_slot->tts_tupleDescriptor;

> +

> +                       Assert(desc->tdrefcount == -1);

> +

>                         ExecDropSingleTupleTableSlot(entry->old_slot);

> +                       FreeTupleDesc(desc);

 

It seems a bit odd because "entry->old_slot->tts_tupleDescriptor" is accessed

after "entry->old_slot" has been freed. I think we can avoid this by assigning

"desc" to NULL before ExecDropSingleTupleTableSlot().

 

```

+                                              TupleDesc       desc = entry->old_slot->tts_tupleDescriptor;

+

+                                              Assert(desc->tdrefcount == -1);

+

+                                              FreeTupleDesc(desc);

+                                              desc = NULL;

                                               ExecDropSingleTupleTableSlot(entry->old_slot);

```

 

By the way, this issue is introduced in 52e4f0cd472d39d. Therefore, we may need

to backport the patch to v15.

 

Best Regards,

Boyu Yang

pgsql-hackers by date:

Previous
From: Kirill Reshke
Date:
Subject: Re: [PATCH] New predefined role pg_manage_extensions
Next
From: Raghu Dev Ramaiah
Date:
Subject: A way to build PSQL 17.1 source on AIX platform