Skip to content
Permalink
Browse files

qgsstyle.cpp: avoid minor memleaks in use of sqlite3_mprintf()

  • Loading branch information
rouault committed Jun 3, 2018
1 parent 79ba0ee commit 8aeb2f6d14d4372595d11822841b6dca1c8646a5
@@ -466,12 +466,11 @@ Is emitted every time a tag or smartgroup has been added, removed, or renamed
Convenience function to open the DB and return a sqlite3 object
%End

bool runEmptyQuery( char *query, bool freeQuery = true );
bool runEmptyQuery( const QString &query );
%Docstring
Convenience function that would run queries which don't generate return values

:param query: query to run
:param freeQuery: release query memory

:return: success true on success
%End
@@ -18,6 +18,7 @@
#include "qgssqliteutils.h"

#include <sqlite3.h>
#include <stdarg.h>

void QgsSqlite3Closer::operator()( sqlite3 *database )
{
@@ -89,3 +90,14 @@ sqlite3_statement_unique_ptr sqlite3_database_unique_ptr::prepare( const QString
s.reset( preparedStatement );
return s;
}

QString QgsSqlite3Mprintf( const char *format, ... )
{
va_list ap;
va_start( ap, format );
char *c_str = sqlite3_vmprintf( format, ap );
va_end( ap );
QString res( QString::fromUtf8( c_str ) );
sqlite3_free( c_str );
return res;
}
@@ -135,7 +135,15 @@ class CORE_EXPORT sqlite3_database_unique_ptr : public std::unique_ptr< sqlite3,
* argument will be filled with the sqlite3 result code.
*/
sqlite3_statement_unique_ptr prepare( const QString &sql, int &resultCode ) const;

};


/**
* Wraps sqlite3_mprintf() by automatically freeing the memory.
* \note not available in Python bindings.
* \since QGIS 3.2
*/
QString CORE_EXPORT QgsSqlite3Mprintf( const char *format, ... );


#endif // QGSSQLITEUTILS_H

0 comments on commit 8aeb2f6

Please sign in to comment.
You can’t perform that action at this time.