summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2020-11-17 02:14:15 +0100
committerLionel Mamane <lionel@mamane.lu>2020-12-18 08:49:56 +0100
commit177792660697f85763b39f455d7ebff0f83084fd (patch)
tree44dc4371cb3189fcd29422e1b91b50d45b243dc2 /connectivity
parentb815bc466695cd1700a2c8d0cdc5201ed5a95032 (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>
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/postgresql/pq_baseresultset.cxx2
-rw-r--r--connectivity/source/drivers/postgresql/pq_connection.cxx3
-rw-r--r--connectivity/source/drivers/postgresql/pq_preparedstatement.cxx2
-rw-r--r--connectivity/source/drivers/postgresql/pq_tools.hxx8
-rw-r--r--connectivity/source/drivers/postgresql/pq_updateableresultset.cxx2
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 5d97f2b2436d..e4716fe8855d 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"
@@ -461,7 +462,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 90490be81eb6..18b105870705 100644
--- a/connectivity/source/drivers/postgresql/pq_tools.hxx
+++ b/connectivity/source/drivers/postgresql/pq_tools.hxx
@@ -51,6 +51,14 @@
#include <string_view>
#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 )