add debugging code to try and find the sqlite3 double-free bug

This commit is contained in:
Ron Pedde 2006-03-06 01:35:49 +00:00
parent cf59f7dc33
commit dad6b9e9d5
2 changed files with 31 additions and 8 deletions

View File

@ -62,7 +62,7 @@ static sqlite3 *db_sqlite3_songs; /**< Database that holds the mp3 info */
static pthread_mutex_t db_sqlite3_mutex = PTHREAD_MUTEX_INITIALIZER; /**< sqlite not reentrant */ static pthread_mutex_t db_sqlite3_mutex = PTHREAD_MUTEX_INITIALIZER; /**< sqlite not reentrant */
static sqlite3_stmt *db_sqlite3_stmt; static sqlite3_stmt *db_sqlite3_stmt;
static int db_sqlite3_reload=0; static int db_sqlite3_reload=0;
static char *db_sqlite3_enum_query; static char *db_sqlite3_enum_query=NULL;
static char **db_sqlite3_row = NULL; static char **db_sqlite3_row = NULL;
static char db_sqlite3_path[PATH_MAX + 1]; static char db_sqlite3_path[PATH_MAX + 1];
@ -229,6 +229,10 @@ int db_sqlite3_enum_begin_helper(char **pe) {
int err; int err;
const char *ptail; const char *ptail;
if(!db_sqlite3_enum_query)
*((int*)NULL) = 1;
DPRINTF(E_DBG,L_DB,"Executing: %s\n",db_sqlite3_enum_query); DPRINTF(E_DBG,L_DB,"Executing: %s\n",db_sqlite3_enum_query);
err=sqlite3_prepare(db_sqlite3_songs,db_sqlite3_enum_query,0, err=sqlite3_prepare(db_sqlite3_songs,db_sqlite3_enum_query,0,
&db_sqlite3_stmt,&ptail); &db_sqlite3_stmt,&ptail);
@ -237,6 +241,7 @@ int db_sqlite3_enum_begin_helper(char **pe) {
db_get_error(pe,DB_E_SQL_ERROR,sqlite3_errmsg(db_sqlite3_songs)); db_get_error(pe,DB_E_SQL_ERROR,sqlite3_errmsg(db_sqlite3_songs));
db_sqlite3_unlock(); db_sqlite3_unlock();
sqlite3_free(db_sqlite3_enum_query); sqlite3_free(db_sqlite3_enum_query);
db_sqlite3_enum_query=NULL;
return DB_E_SQL_ERROR; return DB_E_SQL_ERROR;
} }
@ -250,7 +255,9 @@ int db_sqlite3_enum_begin_helper(char **pe) {
} }
/** /**
* fetch the next row * fetch the next row. This will return DB_E_SUCCESS if it got a
* row, or it's done. If it's done, the row will be empty, otherwise
* it will be full of data. Either way, if fetch fails, you must close.
* *
* @param pe error string, if result isn't DB_E_SUCCESS * @param pe error string, if result isn't DB_E_SUCCESS
* @param pr pointer to a row struct * @param pr pointer to a row struct
@ -265,6 +272,9 @@ int db_sqlite3_enum_fetch(char **pe, SQL_ROW *pr) {
int idx; int idx;
int counter=10; int counter=10;
if(!db_sqlite3_enum_query)
*((int*)NULL) = 1;
while(counter--) { while(counter--) {
err=sqlite3_step(db_sqlite3_stmt); err=sqlite3_step(db_sqlite3_stmt);
if(err != SQLITE_BUSY) if(err != SQLITE_BUSY)
@ -312,10 +322,14 @@ int db_sqlite3_enum_fetch(char **pe, SQL_ROW *pr) {
int db_sqlite3_enum_end(char **pe) { int db_sqlite3_enum_end(char **pe) {
int err; int err;
if(!db_sqlite3_enum_query)
*((int*)NULL) = 1;
if(db_sqlite3_row) if(db_sqlite3_row)
free(db_sqlite3_row); free(db_sqlite3_row);
db_sqlite3_row = NULL; db_sqlite3_row = NULL;
sqlite3_free(db_sqlite3_enum_query); sqlite3_free(db_sqlite3_enum_query);
db_sqlite3_enum_query = NULL;
err = sqlite3_finalize(db_sqlite3_stmt); err = sqlite3_finalize(db_sqlite3_stmt);
if(err != SQLITE_OK) { if(err != SQLITE_OK) {

View File

@ -1257,6 +1257,7 @@ void dispatch_items(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
int song_count; int song_count;
int list_length; int list_length;
unsigned char *block; unsigned char *block;
char *pe;
if(ws_getvar(pwsc,"meta")) { if(ws_getvar(pwsc,"meta")) {
pqi->meta = db_encode_meta(ws_getvar(pwsc,"meta")); pqi->meta = db_encode_meta(ws_getvar(pwsc,"meta"));
@ -1273,7 +1274,12 @@ void dispatch_items(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
} }
/* FIXME: Error handling */ /* FIXME: Error handling */
db_enum_size(NULL,pqi,&song_count,&list_length); if(db_enum_size(&pe,pqi,&song_count,&list_length) != DB_E_SUCCESS) {
DPRINTF(E_LOG,L_DAAP,"Error getting dmap size: %s\n",pe);
song_count=0;
list_length=0;
free(pe);
}
DPRINTF(E_DBG,L_DAAP,"Item enum: got %d songs, dmap size: %d\n",song_count,list_length); DPRINTF(E_DBG,L_DAAP,"Item enum: got %d songs, dmap size: %d\n",song_count,list_length);
@ -1287,18 +1293,21 @@ void dispatch_items(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
dispatch_output_start(pwsc,pqi,61+list_length); dispatch_output_start(pwsc,pqi,61+list_length);
dispatch_output_write(pwsc,pqi,items_response,61); dispatch_output_write(pwsc,pqi,items_response,61);
pe=NULL;
while((db_enum_fetch(NULL,pqi,&list_length,&block) == DB_E_SUCCESS) && while((db_enum_fetch(NULL,pqi,&list_length,&block) == DB_E_SUCCESS) &&
(list_length)) (list_length)) {
{
DPRINTF(E_SPAM,L_DAAP,"Got block of size %d\n",list_length); DPRINTF(E_SPAM,L_DAAP,"Got block of size %d\n",list_length);
dispatch_output_write(pwsc,pqi,block,list_length); dispatch_output_write(pwsc,pqi,block,list_length);
free(block); free(block);
} }
DPRINTF(E_DBG,L_DAAP,"Done enumerating.\n"); DPRINTF(E_DBG,L_DAAP,"Done enumerating.\n");
db_enum_end(NULL); db_enum_end(NULL);
if(pe) {
DPRINTF(E_LOG,L_DAAP,"Error enumerating items: %s\n",pe);
free(pe);
}
dispatch_output_end(pwsc,pqi); dispatch_output_end(pwsc,pqi);
return; return;
} }
@ -1478,7 +1487,7 @@ void dispatch_server_info(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
current += db_dmap_add_string(current,"minm",servername); /* 8 + strlen(name) */ current += db_dmap_add_string(current,"minm",servername); /* 8 + strlen(name) */
current += db_dmap_add_char(current,"msau", /* 9 */ current += db_dmap_add_char(current,"msau", /* 9 */
conf_isset("general","password") ? 2 : 0); conf_isset("general","password") ? 1 : 0);
current += db_dmap_add_char(current,"msex",0); /* 9 */ current += db_dmap_add_char(current,"msex",0); /* 9 */
current += db_dmap_add_char(current,"msix",0); /* 9 */ current += db_dmap_add_char(current,"msix",0); /* 9 */
current += db_dmap_add_char(current,"msbr",0); /* 9 */ current += db_dmap_add_char(current,"msbr",0); /* 9 */