Skip to content

Commit 370bac9

Browse files
authored
Merge pull request #7152 from rouault/fix_memleaks_qgsstyle
Fix various memleaks in QgsStyle
2 parents 88a49e7 + 0304ec4 commit 370bac9

File tree

6 files changed

+147
-169
lines changed

6 files changed

+147
-169
lines changed

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

+1-46
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ returns 0 if not found
134134
Returns default application-wide style
135135
%End
136136

137+
137138
bool tagSymbol( StyleEntity type, const QString &symbol, const QStringList &tags );
138139
%Docstring
139140
Tags the symbol with the tags in the list
@@ -453,56 +454,10 @@ Is emitted every time a new symbol has been added to the database
453454
void groupsModified();
454455
%Docstring
455456
Is emitted every time a tag or smartgroup has been added, removed, or renamed
456-
%End
457-
458-
protected:
459-
460-
461-
462-
463-
464-
bool openDatabase( const QString &filename );
465-
%Docstring
466-
Convenience function to open the DB and return a sqlite3 object
467-
%End
468-
469-
bool runEmptyQuery( char *query, bool freeQuery = true );
470-
%Docstring
471-
Convenience function that would run queries which don't generate return values
472-
473-
:param query: query to run
474-
:param freeQuery: release query memory
475-
476-
:return: success true on success
477-
%End
478-
479-
int getId( const QString &table, const QString &name );
480-
%Docstring
481-
Gets the id from the table for the given name from the database, 0 if not found
482-
%End
483-
484-
QString getName( const QString &table, int id ) const;
485-
%Docstring
486-
Gets the name from the table for the given id from the database, empty if not found
487-
%End
488-
489-
bool updateSymbol( StyleEntity type, const QString &name );
490-
%Docstring
491-
Updates the properties of an existing symbol/colorramp
492-
493-
.. note::
494-
495-
This should not be called separately, only called through addSymbol or addColorRamp
496-
497-
:param type: is either SymbolEntity or ColorrampEntity
498-
:param name: is the name of an existing symbol or a color ramp
499-
500-
:return: Success state of the update operation
501457
%End
502458

503459
};
504460

505-
506461
/************************************************************************
507462
* This file has been generated automatically from *
508463
* *

src/core/qgsapplication.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "qgs3drendererregistry.h"
4848
#include "qgslayoutrendercontext.h"
4949
#include "qgssqliteutils.h"
50+
#include "qgsstyle.h"
5051

5152
#include "gps/qgsgpsconnectionregistry.h"
5253
#include "processing/qgsprocessingregistry.h"
@@ -1089,6 +1090,8 @@ void QgsApplication::exitQgis()
10891090
// is destroyed before the static variables of the cache, we might use freed memory.
10901091
QgsCoordinateTransform::invalidateCache();
10911092

1093+
QgsStyle::cleanDefaultStyle();
1094+
10921095
// tear-down GDAL/OGR
10931096
OGRCleanupAll();
10941097
GDALDestroyDriverManager();

src/core/qgssqliteutils.cpp

+12
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

+9-1
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)