Skip to content

Commit 8aeb2f6

Browse files
committed
qgsstyle.cpp: avoid minor memleaks in use of sqlite3_mprintf()
1 parent 79ba0ee commit 8aeb2f6

File tree

5 files changed

+135
-122
lines changed

5 files changed

+135
-122
lines changed

python/core/auto_generated/symbology/qgsstyle.sip.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,11 @@ Is emitted every time a tag or smartgroup has been added, removed, or renamed
466466
Convenience function to open the DB and return a sqlite3 object
467467
%End
468468

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

473473
:param query: query to run
474-
:param freeQuery: release query memory
475474

476475
:return: success true on success
477476
%End

src/core/qgssqliteutils.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgssqliteutils.h"
1919

2020
#include <sqlite3.h>
21+
#include <stdarg.h>
2122

2223
void QgsSqlite3Closer::operator()( sqlite3 *database )
2324
{
@@ -89,3 +90,14 @@ sqlite3_statement_unique_ptr sqlite3_database_unique_ptr::prepare( const QString
8990
s.reset( preparedStatement );
9091
return s;
9192
}
93+
94+
QString QgsSqlite3Mprintf( const char *format, ... )
95+
{
96+
va_list ap;
97+
va_start( ap, format );
98+
char *c_str = sqlite3_vmprintf( format, ap );
99+
va_end( ap );
100+
QString res( QString::fromUtf8( c_str ) );
101+
sqlite3_free( c_str );
102+
return res;
103+
}

src/core/qgssqliteutils.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,15 @@ class CORE_EXPORT sqlite3_database_unique_ptr : public std::unique_ptr< sqlite3,
135135
* argument will be filled with the sqlite3 result code.
136136
*/
137137
sqlite3_statement_unique_ptr prepare( const QString &sql, int &resultCode ) const;
138-
139138
};
140139

140+
141+
/**
142+
* Wraps sqlite3_mprintf() by automatically freeing the memory.
143+
* \note not available in Python bindings.
144+
* \since QGIS 3.2
145+
*/
146+
QString CORE_EXPORT QgsSqlite3Mprintf( const char *format, ... );
147+
148+
141149
#endif // QGSSQLITEUTILS_H

0 commit comments

Comments
 (0)