Re: [PATCH] Windows port, fix some resources leaks

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Juan José Santamaría Flecha <juanjo(dot)santamaria(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Windows port, fix some resources leaks
Date: 2020-01-21 14:01:07
Message-ID: CAEudQAqMXQGN--zivLNzF2jZ97P=zf0O93dPL+Ej4fK-Mz=cKQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em ter., 21 de jan. de 2020 às 06:18, Juan José Santamaría Flecha <
juanjo(dot)santamaria(at)gmail(dot)com> escreveu:

> Some of the code this patch touches is not windows port only, so the
> subject might be misleading reviewers.
>
True. Some leaks occurs at other platforms.

> It will be easier to review if you break this patch into smaller and
> independent committable patches, as one per file.
>
Done.

I separated the patch, one per file, to facilitate the review according to
your suggestion.
It looked like this:
1. /src/backend/postmaster/postmaster.c
In case of failure, it was necessary to deallocate the param pointer and
release the handle properly.
2. /src/backend/port/win32_shmem.c
In case of failure, the reserved memory can be released immediately, within
the function.
3. /src/common/restricted_token.c
If it is not possible to open the token, better release the dll, we may be
the only one to use it.
If it is not possible to allocate the SID, it was necessary to release the
handle and release the DLL properly.
The cmdline variable has yet to be released.
4. src / backend / regex / rege_dfa.c
The free_dfa function must free the entire structure, including itself.
5. src / backend / regex / regexec.c
The use of the NOERR () macro, hides the return, which causes the failure
to free the memory properly.
6. src / common / logging.c
The strdup function destroys the reference to the old pointer, in case of a
loop, it is necessary to release it beforehand.
The free function with variable NULL, has no effect and can be called
without problems.
7. /src/backend/libpq/auth.c
In case of failure, it was necessary to release the handlers properly.

regards,
Ranier Vilela

Attachment Content-Type Size
postmaster_resource_leak.patch application/octet-stream 1020 bytes
win32_shmem_resource_leak.patch application/octet-stream 720 bytes
restricted_token_resource_leak.patch application/octet-stream 863 bytes
regex_resource_leak.patch application/octet-stream 1.0 KB
logging_resource_leak.patch application/octet-stream 597 bytes
auth_resource_leak.patch application/octet-stream 1.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2020-01-21 14:25:29 Re: [PATCH] Incremental sort (was: PoC: Partial sort)
Previous Message Tomas Vondra 2020-01-21 13:59:51 Re: SLRU statistics