postgresql-interfaces/psqlodbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: ColinKYuen (@ColinKYuen) <[email protected]>
To: postgresql-interfaces/psqlodbc <[email protected]>
Subject: [postgresql-interfaces/psqlodbc] PR #114: fix: use pgfree for libpq mallocs
Date: Thu, 24 Apr 2025 22:09:27 +0000
Message-ID: <[email protected]> (raw)

## Summary

Uses libqpq's Free for libqpq malloc'd String

## Description

Changes the generic `free()` function for the error message string allocated by `PQconninfoParse(..)` to use libpq's `PQfreemem(..)`

As per [PostgreSQL's libqpq documents](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PQCONNINFOPARSE), when using `PQconninfoParse(..)`:

> ... After processing the options array, free it by passing it to [PQconninfoFree](https://www.postgresql.org/docs/current/libpq-misc.html#LIBPQ-PQCONNINFOFREE). If this is not done, some memory is leaked for each call to [PQconninfoParse](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PQCONNINFOPARSE). **Conversely, if an error occurs and errmsg is not NULL, be sure to free the error string using [PQfreemem](https://www.postgresql.org/docs/current/libpq-misc.html#LIBPQ-PQFREEMEM).**

Additional information on [PQfreemem](https://www.postgresql.org/docs/current/libpq-misc.html#LIBPQ-PQFREEMEM), this change is only needed for Windows
> Frees memory allocated by libpq, particularly [PQescapeByteaConn](https://www.postgresql.org/docs/current/libpq-exec.html#LIBPQ-PQESCAPEBYTEACONN), [PQescapeBytea](https://www.postgresql.org/docs/current/libpq-exec.html#LIBPQ-PQESCAPEBYTEA), [PQunescapeBytea](https://www.postgresql.org/docs/current/libpq-exec.html#LIBPQ-PQUNESCAPEBYTEA), and PQnotifies. **It is particularly important that this function, rather than free(), be used on Microsoft Windows**. This is because allocating memory in a DLL and releasing it in the application works only if multithreaded/single-threaded, release/debug, and static/dynamic flags are the same for the DLL and the application. **On non-Microsoft Windows platforms, this function is the same as the standard library function free().**

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://postgresql-interfaces/psqlodbc
  Cc: [email protected], [email protected]
  Subject: Re: [postgresql-interfaces/psqlodbc] PR #114: fix: use pgfree for libpq mallocs
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox