Fossil SCM

Fix harmless memory leaks.

drh 2019-09-24 10:09 trunk
Commit 79988f962e2fa40abf9989ec25f1da0865bc7836947849ca47a1bb8704792e6f
+10 -5
--- src/db.c
+++ src/db.c
@@ -1363,24 +1363,25 @@
13631363
*/
13641364
void db_close_config(){
13651365
int iSlot = db_database_slot("configdb");
13661366
if( iSlot>0 ){
13671367
db_detach("configdb");
1368
- g.zConfigDbName = 0;
13691368
}else if( g.dbConfig ){
13701369
sqlite3_wal_checkpoint(g.dbConfig, 0);
13711370
sqlite3_close(g.dbConfig);
13721371
g.dbConfig = 0;
1373
- g.zConfigDbName = 0;
13741372
}else if( g.db && 0==iSlot ){
13751373
int rc;
13761374
sqlite3_wal_checkpoint(g.db, 0);
13771375
rc = sqlite3_close(g.db);
13781376
if( g.fSqlTrace ) fossil_trace("-- db_close_config(%d)\n", rc);
13791377
g.db = 0;
1380
- g.zConfigDbName = 0;
1378
+ }else{
1379
+ return;
13811380
}
1381
+ fossil_free(g.zConfigDbName);
1382
+ g.zConfigDbName = 0;
13821383
}
13831384
13841385
/*
13851386
** Open the user database in "~/.fossil". Create the database anew if
13861387
** it does not already exist.
@@ -2731,12 +2732,16 @@
27312732
db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
27322733
}
27332734
}
27342735
int db_get_boolean(const char *zName, int dflt){
27352736
char *zVal = db_get(zName, dflt ? "on" : "off");
2736
- if( is_truth(zVal) ) return 1;
2737
- if( is_false(zVal) ) return 0;
2737
+ if( is_truth(zVal) ){
2738
+ dflt = 1;
2739
+ }else if( is_false(zVal) ){
2740
+ dflt = 0;
2741
+ }
2742
+ fossil_free(zVal);
27382743
return dflt;
27392744
}
27402745
int db_get_versioned_boolean(const char *zName, int dflt){
27412746
char *zVal = db_get_versioned(zName, 0);
27422747
if( zVal==0 ) return dflt;
27432748
--- src/db.c
+++ src/db.c
@@ -1363,24 +1363,25 @@
1363 */
1364 void db_close_config(){
1365 int iSlot = db_database_slot("configdb");
1366 if( iSlot>0 ){
1367 db_detach("configdb");
1368 g.zConfigDbName = 0;
1369 }else if( g.dbConfig ){
1370 sqlite3_wal_checkpoint(g.dbConfig, 0);
1371 sqlite3_close(g.dbConfig);
1372 g.dbConfig = 0;
1373 g.zConfigDbName = 0;
1374 }else if( g.db && 0==iSlot ){
1375 int rc;
1376 sqlite3_wal_checkpoint(g.db, 0);
1377 rc = sqlite3_close(g.db);
1378 if( g.fSqlTrace ) fossil_trace("-- db_close_config(%d)\n", rc);
1379 g.db = 0;
1380 g.zConfigDbName = 0;
 
1381 }
 
 
1382 }
1383
1384 /*
1385 ** Open the user database in "~/.fossil". Create the database anew if
1386 ** it does not already exist.
@@ -2731,12 +2732,16 @@
2731 db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
2732 }
2733 }
2734 int db_get_boolean(const char *zName, int dflt){
2735 char *zVal = db_get(zName, dflt ? "on" : "off");
2736 if( is_truth(zVal) ) return 1;
2737 if( is_false(zVal) ) return 0;
 
 
 
 
2738 return dflt;
2739 }
2740 int db_get_versioned_boolean(const char *zName, int dflt){
2741 char *zVal = db_get_versioned(zName, 0);
2742 if( zVal==0 ) return dflt;
2743
--- src/db.c
+++ src/db.c
@@ -1363,24 +1363,25 @@
1363 */
1364 void db_close_config(){
1365 int iSlot = db_database_slot("configdb");
1366 if( iSlot>0 ){
1367 db_detach("configdb");
 
1368 }else if( g.dbConfig ){
1369 sqlite3_wal_checkpoint(g.dbConfig, 0);
1370 sqlite3_close(g.dbConfig);
1371 g.dbConfig = 0;
 
1372 }else if( g.db && 0==iSlot ){
1373 int rc;
1374 sqlite3_wal_checkpoint(g.db, 0);
1375 rc = sqlite3_close(g.db);
1376 if( g.fSqlTrace ) fossil_trace("-- db_close_config(%d)\n", rc);
1377 g.db = 0;
1378 }else{
1379 return;
1380 }
1381 fossil_free(g.zConfigDbName);
1382 g.zConfigDbName = 0;
1383 }
1384
1385 /*
1386 ** Open the user database in "~/.fossil". Create the database anew if
1387 ** it does not already exist.
@@ -2731,12 +2732,16 @@
2732 db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
2733 }
2734 }
2735 int db_get_boolean(const char *zName, int dflt){
2736 char *zVal = db_get(zName, dflt ? "on" : "off");
2737 if( is_truth(zVal) ){
2738 dflt = 1;
2739 }else if( is_false(zVal) ){
2740 dflt = 0;
2741 }
2742 fossil_free(zVal);
2743 return dflt;
2744 }
2745 int db_get_versioned_boolean(const char *zName, int dflt){
2746 char *zVal = db_get_versioned(zName, 0);
2747 if( zVal==0 ) return dflt;
2748
+1 -1
--- src/main.c
+++ src/main.c
@@ -149,11 +149,11 @@
149149
const char *zVfsName; /* The VFS to use for database connections */
150150
sqlite3 *db; /* The connection to the databases */
151151
sqlite3 *dbConfig; /* Separate connection for global_config table */
152152
char *zAuxSchema; /* Main repository aux-schema */
153153
int dbIgnoreErrors; /* Ignore database errors if true */
154
- const char *zConfigDbName;/* Path of the config database. NULL if not open */
154
+ char *zConfigDbName; /* Path of the config database. NULL if not open */
155155
sqlite3_int64 now; /* Seconds since 1970 */
156156
int repositoryOpen; /* True if the main repository database is open */
157157
unsigned iRepoDataVers; /* Initial data version for repository database */
158158
char *zRepositoryOption; /* Most recent cached repository option value */
159159
char *zRepositoryName; /* Name of the repository database file */
160160
--- src/main.c
+++ src/main.c
@@ -149,11 +149,11 @@
149 const char *zVfsName; /* The VFS to use for database connections */
150 sqlite3 *db; /* The connection to the databases */
151 sqlite3 *dbConfig; /* Separate connection for global_config table */
152 char *zAuxSchema; /* Main repository aux-schema */
153 int dbIgnoreErrors; /* Ignore database errors if true */
154 const char *zConfigDbName;/* Path of the config database. NULL if not open */
155 sqlite3_int64 now; /* Seconds since 1970 */
156 int repositoryOpen; /* True if the main repository database is open */
157 unsigned iRepoDataVers; /* Initial data version for repository database */
158 char *zRepositoryOption; /* Most recent cached repository option value */
159 char *zRepositoryName; /* Name of the repository database file */
160
--- src/main.c
+++ src/main.c
@@ -149,11 +149,11 @@
149 const char *zVfsName; /* The VFS to use for database connections */
150 sqlite3 *db; /* The connection to the databases */
151 sqlite3 *dbConfig; /* Separate connection for global_config table */
152 char *zAuxSchema; /* Main repository aux-schema */
153 int dbIgnoreErrors; /* Ignore database errors if true */
154 char *zConfigDbName; /* Path of the config database. NULL if not open */
155 sqlite3_int64 now; /* Seconds since 1970 */
156 int repositoryOpen; /* True if the main repository database is open */
157 unsigned iRepoDataVers; /* Initial data version for repository database */
158 char *zRepositoryOption; /* Most recent cached repository option value */
159 char *zRepositoryName; /* Name of the repository database file */
160
+2 -2
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -302,21 +302,21 @@
302302
** symbolic_name_to_rid(X) Return the BLOB.RID corresponding to symbolic
303303
** name X.
304304
*/
305305
void cmd_sqlite3(void){
306306
int noRepository;
307
- const char *zConfigDb;
307
+ char *zConfigDb;
308308
extern int sqlite3_shell(int, char**);
309309
#ifdef FOSSIL_ENABLE_TH1_HOOKS
310310
g.fNoThHook = 1;
311311
#endif
312312
noRepository = find_option("no-repository", 0, 0)!=0;
313313
if( !noRepository ){
314314
db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
315315
}
316316
db_open_config(1,0);
317
- zConfigDb = g.zConfigDbName;
317
+ zConfigDb = fossil_strdup(g.zConfigDbName);
318318
fossil_close(1, noRepository);
319319
sqlite3_shutdown();
320320
#ifndef _WIN32
321321
linenoiseSetMultiLine(1);
322322
#endif
323323
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -302,21 +302,21 @@
302 ** symbolic_name_to_rid(X) Return the BLOB.RID corresponding to symbolic
303 ** name X.
304 */
305 void cmd_sqlite3(void){
306 int noRepository;
307 const char *zConfigDb;
308 extern int sqlite3_shell(int, char**);
309 #ifdef FOSSIL_ENABLE_TH1_HOOKS
310 g.fNoThHook = 1;
311 #endif
312 noRepository = find_option("no-repository", 0, 0)!=0;
313 if( !noRepository ){
314 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
315 }
316 db_open_config(1,0);
317 zConfigDb = g.zConfigDbName;
318 fossil_close(1, noRepository);
319 sqlite3_shutdown();
320 #ifndef _WIN32
321 linenoiseSetMultiLine(1);
322 #endif
323
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -302,21 +302,21 @@
302 ** symbolic_name_to_rid(X) Return the BLOB.RID corresponding to symbolic
303 ** name X.
304 */
305 void cmd_sqlite3(void){
306 int noRepository;
307 char *zConfigDb;
308 extern int sqlite3_shell(int, char**);
309 #ifdef FOSSIL_ENABLE_TH1_HOOKS
310 g.fNoThHook = 1;
311 #endif
312 noRepository = find_option("no-repository", 0, 0)!=0;
313 if( !noRepository ){
314 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
315 }
316 db_open_config(1,0);
317 zConfigDb = fossil_strdup(g.zConfigDbName);
318 fossil_close(1, noRepository);
319 sqlite3_shutdown();
320 #ifndef _WIN32
321 linenoiseSetMultiLine(1);
322 #endif
323
+2
--- src/wiki.c
+++ src/wiki.c
@@ -1636,10 +1636,12 @@
16361636
if( g.argc!=3 ) usage("FILE");
16371637
blob_zero(&out);
16381638
blob_read_from_file(&in, g.argv[2], ExtFILE);
16391639
markdown_to_html(&in, 0, &out);
16401640
blob_write_to_file(&out, "-");
1641
+ blob_reset(&in);
1642
+ blob_reset(&out);
16411643
}
16421644
16431645
/*
16441646
** Allowed flags for wiki_render_associated
16451647
*/
16461648
--- src/wiki.c
+++ src/wiki.c
@@ -1636,10 +1636,12 @@
1636 if( g.argc!=3 ) usage("FILE");
1637 blob_zero(&out);
1638 blob_read_from_file(&in, g.argv[2], ExtFILE);
1639 markdown_to_html(&in, 0, &out);
1640 blob_write_to_file(&out, "-");
 
 
1641 }
1642
1643 /*
1644 ** Allowed flags for wiki_render_associated
1645 */
1646
--- src/wiki.c
+++ src/wiki.c
@@ -1636,10 +1636,12 @@
1636 if( g.argc!=3 ) usage("FILE");
1637 blob_zero(&out);
1638 blob_read_from_file(&in, g.argv[2], ExtFILE);
1639 markdown_to_html(&in, 0, &out);
1640 blob_write_to_file(&out, "-");
1641 blob_reset(&in);
1642 blob_reset(&out);
1643 }
1644
1645 /*
1646 ** Allowed flags for wiki_render_associated
1647 */
1648

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button