Fix frees for nulled error pointers, other minor problems

This commit is contained in:
Ron Pedde 2006-01-04 23:46:15 +00:00
parent 86b45a028e
commit 1418a64dc9
3 changed files with 28 additions and 25 deletions

View File

@ -389,6 +389,8 @@ void db_get_error(char **pe, int error, ...) {
vsnprintf(errbuf, sizeof(errbuf), db_error_list[error], ap);
va_end(ap);
DPRINTF(E_SPAM,L_MISC,"Raising error: %s\n",errbuf);
*pe = strdup(errbuf);
}

View File

@ -136,19 +136,18 @@ int db_sqlite2_open(char **pe, char *dsn) {
}
sqlite_busy_timeout(db_sqlite2_songs,30000); /* 30 seconds */
db_sqlite2_unlock();
err = db_sql_fetch_int(pe,&ver,"select value from config where term='version'");
err = db_sql_fetch_int(pe,&ver,"select value from config where "
"term='version'");
if(err != DB_E_SUCCESS) {
free(*pe);
/* create the table */
DPRINTF(E_FATAL,L_DB,"Can't create table yet!\n");
}
if(ver != DB_SQLITE2_VERSION) {
if(pe) { free(*pe); }
/* we'll catch this on the init */
DPRINTF(E_LOG,L_DB,"Can't get db version. New database?\n");
} else if(ver != DB_SQLITE2_VERSION) {
DPRINTF(E_FATAL,L_DB,"Can't upgrade database!\n");
}
db_sqlite2_unlock();
return DB_E_SUCCESS;
}
@ -221,10 +220,11 @@ int db_sqlite2_enum_begin(char **pe, char *fmt, ...) {
va_end(ap);
}
DPRINTF(E_DBG,L_DB,"Executing :%s\n",db_sqlite2_enum_query);
DPRINTF(E_DBG,L_DB,"Executing: %s\n",db_sqlite2_enum_query);
db_sqlite2_in_enum=1;
err=sqlite_compile(db_sqlite2_songs,db_sqlite2_enum_query,&ptail,&db_sqlite2_pvm,&perr);
err=sqlite_compile(db_sqlite2_songs,db_sqlite2_enum_query,
&ptail,&db_sqlite2_pvm,&perr);
if(err != SQLITE_OK) {
db_get_error(pe,DB_E_SQL_ERROR,perr);
@ -315,9 +315,9 @@ int db_sqlite2_event(int event_type) {
break;
case DB_SQL_EVENT_FULLRELOAD: /* either a fresh load or force load */
db_sqlite2_exec(NULL,E_DBG,"delete index idx_path");
db_sqlite2_exec(NULL,E_DBG,"delete index idx_songid");
db_sqlite2_exec(NULL,E_DBG,"delete index idx_playlistid");
db_sqlite2_exec(NULL,E_DBG,"drop index idx_path");
db_sqlite2_exec(NULL,E_DBG,"drop index idx_songid");
db_sqlite2_exec(NULL,E_DBG,"drop index idx_playlistid");
db_sqlite2_exec(NULL,E_DBG,"drop table songs");
db_sqlite2_exec(NULL,E_DBG,"drop table playlists");
@ -447,7 +447,7 @@ char *db_initial =
" path VARCHAR(4096),\n"
" idx INTEGER NOT NULL\n"
");\n"
"insert into config values ('version','','1');\n"
"insert into config values ('version','','8');\n"
"insert into playlists values (1,'Library',1,0,'1',0,'',0);\n"
"create index idx_path on songs(path);\n"
"create index idx_songid on playlistitems(songid);\n"

View File

@ -72,7 +72,9 @@ int db_sql_fetch_row(char **pe, SQL_ROW *row, char *fmt, ...) {
char *query;
va_list ap;
db_sql_need_dispose = 0;
*row=NULL;
va_start(ap,fmt);
query=db_sqlite2_vmquery(fmt,ap);
@ -81,7 +83,6 @@ int db_sql_fetch_row(char **pe, SQL_ROW *row, char *fmt, ...) {
err=db_sqlite2_enum_begin(pe,query);
db_sqlite2_vmfree(query);
if(err != DB_E_SUCCESS) {
return err;
}
@ -92,7 +93,7 @@ int db_sql_fetch_row(char **pe, SQL_ROW *row, char *fmt, ...) {
return err;
}
if(!row) {
if(!(*row)) {
db_sqlite2_enum_end(NULL);
db_get_error(pe,DB_E_NOROWS);
return DB_E_NOROWS;
@ -298,7 +299,7 @@ int db_sql_delete_playlist(char **pe, int playlistid) {
if(result != DB_E_SUCCESS) {
if(result == DB_E_NOROWS) { /* Override the generic error */
free(*pe);
if(pe) { free(*pe); };
db_get_error(pe,DB_E_INVALID_PLAYLIST);
return DB_E_INVALID_PLAYLIST;
}
@ -332,7 +333,7 @@ int db_sql_delete_playlist_item(char **pe, int playlistid, int songid) {
if(result != DB_E_SUCCESS) {
if(result == DB_E_NOROWS) { /* Override generic error */
free(*pe);
if(pe) { free(*pe); };
db_get_error(pe,DB_E_INVALID_PLAYLIST);
return DB_E_INVALID_PLAYLIST;
}
@ -351,7 +352,7 @@ int db_sql_delete_playlist_item(char **pe, int playlistid, int songid) {
if(result != DB_E_SUCCESS) {
if(result == DB_E_NOROWS) { /* Override generic error */
free(*pe);
if(pe) { free(*pe); };
db_get_error(pe,DB_E_INVALID_SONGID);
return DB_E_INVALID_SONGID;
}
@ -384,7 +385,7 @@ int db_sql_edit_playlist(char **pe, int id, char *name, char *clause) {
if(result != DB_E_SUCCESS) {
if(result == DB_E_NOROWS) { /* Override generic error */
free(*pe);
if(pe) { free(*pe); };
db_get_error(pe,DB_E_INVALID_PLAYLIST);
return DB_E_INVALID_PLAYLIST;
}
@ -419,7 +420,7 @@ int db_sql_add_playlist(char **pe, char *name, int type, char *clause, char *pat
"upper(title)=upper('%q')",name);
if(result == DB_E_NOROWS) { /* good playlist name */
free(*pe);
if(pe) { free(*pe); };
} else {
if(result != DB_E_SUCCESS) {
return result;
@ -493,7 +494,7 @@ int db_sql_add_playlist_item(char **pe, int playlistid, int songid) {
if(result != DB_E_SUCCESS) {
if(result == DB_E_NOROWS) { /* Override generic error */
free(*pe);
if(pe) { free(*pe); };
db_get_error(pe,DB_E_INVALID_PLAYLIST);
return DB_E_INVALID_PLAYLIST;
}
@ -511,7 +512,7 @@ int db_sql_add_playlist_item(char **pe, int playlistid, int songid) {
if(result != DB_E_SUCCESS) {
if(result == DB_E_NOROWS) { /* Override generic error */
free(*pe);
if(pe) { free(*pe); };
db_get_error(pe,DB_E_INVALID_SONGID);
return DB_E_INVALID_SONGID;
}
@ -1514,7 +1515,7 @@ MP3FILE *db_sql_fetch_item(char **pe, int id) {
err=db_sql_fetch_row(pe,&row,"select * from songs where id=%d",id);
if(err != DB_E_SUCCESS) {
if(err == DB_E_NOROWS) { /* Override generic error */
free(*pe);
if(pe) { free(*pe); };
db_get_error(pe,DB_E_INVALID_SONGID);
return NULL;
}
@ -1549,7 +1550,7 @@ MP3FILE *db_sql_fetch_path(char **pe, char *path, int index) {
err=db_sql_fetch_row(pe,&row,"select * from songs where path='%q'",path);
if(err != DB_E_SUCCESS) {
if(err == DB_E_NOROWS) { /* Override generic error */
free(*pe);
if(pe) { free(*pe); };
db_get_error(pe,DB_E_INVALID_SONGID);
return NULL;
}