connectivity/source/drivers/postgresql/pq_baseresultset.cxx       |    2 +-
 connectivity/source/drivers/postgresql/pq_connection.cxx          |    9 
+++++----
 connectivity/source/drivers/postgresql/pq_preparedstatement.cxx   |    3 +--
 connectivity/source/drivers/postgresql/pq_tools.hxx               |    8 
++++++++
 connectivity/source/drivers/postgresql/pq_updateableresultset.cxx |    2 +-
 5 files changed, 16 insertions(+), 8 deletions(-)

New commits:
commit 13091c7cf527a04cc373042370c4d4bbda839ba9
Author:     Lionel Elie Mamane <lio...@mamane.lu>
AuthorDate: Tue Nov 17 02:14:15 2020 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Thu Jan 28 10:55:41 2021 +0100

    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
    (cherry picked from commit 177792660697f85763b39f455d7ebff0f83084fd)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107907
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

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 66c30c893aed..9a51f0cd2833 100644
--- a/connectivity/source/drivers/postgresql/pq_connection.cxx
+++ b/connectivity/source/drivers/postgresql/pq_connection.cxx
@@ -42,6 +42,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"
@@ -216,7 +217,7 @@ Reference< XPreparedStatement > 
Connection::prepareStatement( const OUString& sq
     MutexGuard guard( m_xMutex->GetMutex() );
     checkClosed();
 
-    OString byteSql = OUStringToOString( sql, ConnectionSettings::encoding );
+    OString byteSql = rtl::OUStringToOString( sql, 
ConnectionSettings::encoding );
     PreparedStatement *stmt = new PreparedStatement( m_xMutex, this, 
&m_settings, byteSql );
     Reference< XPreparedStatement > ret = stmt;
 
@@ -414,7 +415,7 @@ static void properties2arrays( const Sequence< 
PropertyValue > & args,
         {
             OUString value;
             tc->convertTo( prop.Value, cppu::UnoType<decltype(value)>::get() ) 
>>= value;
-            char *v = strdup(OUStringToOString(value, enc).getStr());
+            char *v = strdup(rtl::OUStringToOString(value, enc).getStr());
             values.push_back ( v );
         }
         else
@@ -460,7 +461,7 @@ void Connection::initialize( const Sequence< Any >& 
aArguments )
         nColon = url.indexOf( ':' , 1+ nColon );
         if( nColon != -1 )
         {
-             o = OUStringToOString( url.getStr()+nColon+1, 
ConnectionSettings::encoding );
+             o = rtl::OUStringToOString( url.getStr()+nColon+1, 
ConnectionSettings::encoding );
         }
     }
     {
@@ -477,7 +478,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 2e352320353f..069cdfa13e35 100644
--- a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
+++ b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
@@ -479,8 +479,7 @@ void PreparedStatement::setBytes(
     checkClosed();
     checkColumnIndex( parameterIndex );
     size_t len;
-    struct Free { void operator ()(void * p) const { free(p); } };
-    std::unique_ptr<unsigned char, Free> 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 )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to