Skip to content
Snippets Groups Projects
Commit e9b90f39 authored by Marcin's avatar Marcin
Browse files

fix for gcc warning about mismatch between memory allocationd and its freeing

parent e6803dce
No related branches found
No related tags found
1 merge request!635Draft: fix for gcc warning about mismatch between memory allocationd and its freeing
Pipeline #118830 passed
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
#include <memory> #include <memory>
namespace PsqlTools::PsqlUtils { namespace PsqlTools::PsqlUtils {
using bytea_ptr = std::unique_ptr< bytea, decltype(&std::free) >;
template< typename _Data > template< typename _Data >
std::unique_ptr< bytea > toBytea( _Data* _data ) { bytea_ptr toBytea( _Data* _data ) {
std::unique_ptr< bytea > result( ( bytea* )new uint8_t[ sizeof( _Data ) + VARHDRSZ ] );
bytea_ptr result( static_cast<bytea*>( std::malloc(sizeof(_Data) + VARHDRSZ) ), &std::free );
SET_VARSIZE( result.get(), sizeof( _Data ) ); SET_VARSIZE( result.get(), sizeof( _Data ) );
std::memcpy( VARDATA_ANY( result.get() ), _data, sizeof( _Data ) ); std::memcpy( VARDATA_ANY( result.get() ), _data, sizeof( _Data ) );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment