Fix a resource leak (src/backend/utils/adt/rowtypes.c)

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Fix a resource leak (src/backend/utils/adt/rowtypes.c)
Date: 2025-04-13 23:34:48
Message-ID: CAEudQApNjhD49jjjPpu0ykG+qLVMQdMa_SBPn9yXhAPL0E4__Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi.

Per Coverity.

CID 1608916: (#1 of 1): Resource leak (RESOURCE_LEAK)
52. leaked_storage: Variable buf going out of scope leaks the storage
buf.data points to.

The function *record_in* has a new report about resource leak.
I think Coverity is right.
The normal path of the function frees the memory of several variables used.
Therefore the failure path should also free them.
A quick search on the web shows several occurrences of "malformed record
literal", therefore failure is common in this function.

Although Coveriy reports the leak of only buf.data, the variables *values*
and *nulls* should also be released.

While there, move the creation of stringdata, to ensure that in case of
failure, the buf.data variable is released correctly.

Attached a path.

best regards,
Ranier Vilela

Attachment Content-Type Size
fix-resource-leak-rowtypes.patch application/octet-stream 933 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-04-14 00:19:35 Re: Back-patch of: avoid multiple hard links to same WAL file after a crash
Previous Message Peter Smith 2025-04-13 23:01:36 Re: Logical Replication of sequences