summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-06-22 14:47:27 +0200
committerStephan Bergmann <sbergman@redhat.com>2020-06-22 15:49:04 +0200
commit921ee37ea3b648e210ecaff21074456c09b91882 (patch)
tree0874fdb3851845a14107a9fe80839e0fd7cfa70a
parent65b5a9848bd01cabbbee8f6e751679a04c1da10f (diff)
Consolidate unique_ptr deleters calling free
Change-Id: I57a977dbb521270a466d464df8c31c364179ec20 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96854 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r--connectivity/source/drivers/postgresql/pq_preparedstatement.cxx4
-rw-r--r--include/o3tl/deleter.hxx9
-rw-r--r--tools/qa/cppunit/test_json_writer.cxx10
3 files changed, 14 insertions, 9 deletions
diff --git a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
index 2e352320353f..30d386a6cd3c 100644
--- a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
+++ b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
@@ -40,6 +40,7 @@
#include "pq_statics.hxx"
#include "pq_statement.hxx"
+#include <o3tl/deleter.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx>
@@ -479,8 +480,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(
+ std::unique_ptr<unsigned char, o3tl::free_delete> escapedString(
PQescapeBytea( reinterpret_cast<unsigned char const *>(x.getConstArray()), x.getLength(), &len));
if( ! escapedString )
{
diff --git a/include/o3tl/deleter.hxx b/include/o3tl/deleter.hxx
index 4e90ca5a61f6..72d13d086de1 100644
--- a/include/o3tl/deleter.hxx
+++ b/include/o3tl/deleter.hxx
@@ -10,6 +10,10 @@
#ifndef INCLUDED_O3TL_DELETER_HXX
#define INCLUDED_O3TL_DELETER_HXX
+#include <sal/config.h>
+
+#include <cstdlib>
+
#include <com/sun/star/uno/Exception.hpp>
#include <sal/log.hxx>
@@ -44,6 +48,11 @@ template<typename T> struct default_delete
}
};
+struct free_delete
+{
+ void operator()(void* p) { std::free(p); }
+};
+
template<typename uniqueptr> void reset_preserve_ptr_during(uniqueptr& ptr)
{
// HACK: for the case where the dtor of the obj held by ptr will trigger
diff --git a/tools/qa/cppunit/test_json_writer.cxx b/tools/qa/cppunit/test_json_writer.cxx
index 6a2cc7813574..6d473e605497 100644
--- a/tools/qa/cppunit/test_json_writer.cxx
+++ b/tools/qa/cppunit/test_json_writer.cxx
@@ -12,6 +12,7 @@
#include <cstdlib>
#include <cppunit/extensions/HelperMacros.h>
+#include <o3tl/deleter.hxx>
#include <test/bootstrapfixture.hxx>
#include <rtl/ustring.hxx>
#include <tools/stream.hxx>
@@ -38,11 +39,6 @@ public:
CPPUNIT_TEST_SUITE_END();
};
-struct Free
-{
- void operator()(void* p) const { std::free(p); }
-};
-
void JsonWriterTest::test1()
{
tools::JsonWriter aJson;
@@ -55,7 +51,7 @@ void JsonWriterTest::test1()
aJson.put("int", 12);
}
- std::unique_ptr<char, Free> result(aJson.extractData());
+ std::unique_ptr<char, o3tl::free_delete> result(aJson.extractData());
CPPUNIT_ASSERT_EQUAL(std::string("{ \"node\": { \"oustring\": \"val1\", \"ostring\": \"val2\", "
"\"charptr\": \"val3\", \"int\": 12}}"),
@@ -81,7 +77,7 @@ void JsonWriterTest::test2()
}
}
- std::unique_ptr<char, Free> result(aJson.extractData());
+ std::unique_ptr<char, o3tl::free_delete> result(aJson.extractData());
CPPUNIT_ASSERT_EQUAL(std::string("{ \"node\": { \"field1\": \"val1\", \"field2\": \"val2\", "
"\"node\": { \"field3\": \"val3\", \"node\": { \"field4\": "