diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2020-11-17 02:14:15 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@cib.de> | 2020-12-18 18:56:32 +0100 |
commit | 1ab014ddf72dd09b2ef30320b8b2936a26923b3a (patch) | |
tree | 3a197aef801af039200aa86250ebc50cb85fec0a /connectivity | |
parent | ee601c71908dc05fb0f3bd6c4916041d889e96e2 (diff) |
pgsql-sdbc: use libpq's custom free()...
... for stuff allocated by libpq
Their documentation says this is important on Microsoft Windows:
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.
Also use const unique_ptr since we don't need the value to survive the
scope in any way.
Change-Id: If4637ea0cd1c05125d63e2f3d37dbeaf716973f9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105967
Tested-by: Lionel Mamane <lionel@mamane.lu>
Reviewed-by: Lionel Mamane <lionel@mamane.lu>
(cherry picked from commit 177792660697f85763b39f455d7ebff0f83084fd)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107906
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Diffstat (limited to 'connectivity')
5 files changed, 13 insertions, 4 deletions
diff --git a/connectivity/source/drivers/postgresql/pq_baseresultset.cxx b/connectivity/source/drivers/postgresql/pq_baseresultset.cxx index 8fc7140e4817..9ff5e01e098a 100644 --- a/connectivity/source/drivers/postgresql/pq_baseresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_baseresultset.cxx @@ -456,7 +456,7 @@ Sequence< sal_Int8 > BaseResultSet::getBytes( sal_Int32 columnIndex ) char * res = reinterpret_cast<char*>(PQunescapeBytea( reinterpret_cast<unsigned char const *>(val.getStr()), &length)); ret = Sequence< sal_Int8 > ( reinterpret_cast<sal_Int8*>(res), length ); if( res ) - free( res ); + PQfreemem( res ); } return ret; } diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx b/connectivity/source/drivers/postgresql/pq_connection.cxx index d9889dea8091..ed3ed85e9c6c 100644 --- a/connectivity/source/drivers/postgresql/pq_connection.cxx +++ b/connectivity/source/drivers/postgresql/pq_connection.cxx @@ -41,6 +41,7 @@ #include "pq_connection.hxx" #include "pq_statement.hxx" +#include "pq_tools.hxx" #include "pq_preparedstatement.hxx" #include "pq_databasemetadata.hxx" #include "pq_xtables.hxx" @@ -460,7 +461,7 @@ void Connection::initialize( const Sequence< Any >& aArguments ) if ( err != nullptr) { errorMessage = OUString( err, strlen(err), ConnectionSettings::encoding ); - free(err); + PQfreemem(err); } else errorMessage = "#no error message#"; diff --git a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx index c1d9a4f66731..344c27175850 100644 --- a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx +++ b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx @@ -481,7 +481,7 @@ void PreparedStatement::setBytes( checkClosed(); checkColumnIndex( parameterIndex ); size_t len; - std::unique_ptr<unsigned char, o3tl::free_delete> escapedString( + const std::unique_ptr<unsigned char, deleter_from_fn<PQfreemem>> escapedString( PQescapeBytea( reinterpret_cast<unsigned char const *>(x.getConstArray()), x.getLength(), &len)); if( ! escapedString ) { diff --git a/connectivity/source/drivers/postgresql/pq_tools.hxx b/connectivity/source/drivers/postgresql/pq_tools.hxx index af751f8e633b..7fbdb260d30b 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.hxx +++ b/connectivity/source/drivers/postgresql/pq_tools.hxx @@ -49,6 +49,14 @@ #include "pq_connection.hxx" #include <vector> +namespace +{ +// helper to create one-time deleters +template <auto fn> +using deleter_from_fn = std::integral_constant<decltype(fn), fn>; + +} + namespace pq_sdbc_driver { bool isWhitespace( sal_Unicode c ); diff --git a/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx b/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx index 880adc647c7e..d8780e76c563 100644 --- a/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_updateableresultset.cxx @@ -481,7 +481,7 @@ void UpdateableResultSet::updateBytes( sal_Int32 columnIndex, const css::uno::Se m_updateableField[columnIndex-1].value <<= OUString( reinterpret_cast<char*>(escapedString), len, RTL_TEXTENCODING_ASCII_US ); - free( escapedString ); + PQfreemem( escapedString ); } void UpdateableResultSet::updateDate( sal_Int32 columnIndex, const css::util::Date& x ) |