From e9b90f39adffd75b11a4401534abc97894178edc Mon Sep 17 00:00:00 2001
From: Marcin Ickiewicz <mickiewicz@syncad.com>
Date: Wed, 26 Mar 2025 12:28:50 +0100
Subject: [PATCH] fix for gcc warning about mismatch between memory allocationd
 and its freeing

---
 src/psql_utils/include/psql_utils/to_bytea.hpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/psql_utils/include/psql_utils/to_bytea.hpp b/src/psql_utils/include/psql_utils/to_bytea.hpp
index 652801be8..d4d01ef44 100644
--- a/src/psql_utils/include/psql_utils/to_bytea.hpp
+++ b/src/psql_utils/include/psql_utils/to_bytea.hpp
@@ -5,10 +5,12 @@
 #include <memory>
 
 namespace PsqlTools::PsqlUtils {
+    using bytea_ptr = std::unique_ptr< bytea, decltype(&std::free) >;
 
     template< typename _Data >
-    std::unique_ptr< bytea > toBytea( _Data* _data ) {
-      std::unique_ptr< bytea > result( ( bytea* )new uint8_t[ sizeof( _Data ) + VARHDRSZ ] );
+    bytea_ptr toBytea( _Data* _data ) {
+
+      bytea_ptr result( static_cast<bytea*>( std::malloc(sizeof(_Data) + VARHDRSZ) ), &std::free );
       SET_VARSIZE( result.get(), sizeof( _Data ) );
       std::memcpy( VARDATA_ANY( result.get() ), _data, sizeof( _Data ) );
 
-- 
GitLab