From 035fd35ffde09dceb3cd6079de5988720bc6395c Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Tue, 6 Nov 2012 08:24:37 +0000 Subject: [PATCH] * Fix up bad accesses found by valgrind. --- minidlna.c | 14 ++++++++------ tagutils/tagutils-wav.c | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/minidlna.c b/minidlna.c index 461a502..dbf7f13 100644 --- a/minidlna.c +++ b/minidlna.c @@ -312,7 +312,7 @@ getfriendlyname(char * buf, int len) } static int -open_db(void) +open_db(sqlite3 **thisdb) { char path[PATH_MAX]; int new_db = 0; @@ -327,11 +327,14 @@ open_db(void) { DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to open sqlite database! Exiting...\n"); } + if (thisdb) + *thisdb = db; sqlite3_busy_timeout(db, 5000); sql_exec(db, "pragma page_size = 4096"); sql_exec(db, "pragma journal_mode = OFF"); sql_exec(db, "pragma synchronous = OFF;"); sql_exec(db, "pragma default_cache_size = 8192;"); + return new_db; } @@ -373,14 +376,14 @@ check_db(sqlite3 *db, int new_db, pid_t *scanner_pid) if( system(cmd) != 0 ) DPRINTF(E_FATAL, L_GENERAL, "Failed to clean old file cache! Exiting...\n"); - open_db(); + open_db(&db); if( CreateDatabase() != 0 ) DPRINTF(E_FATAL, L_GENERAL, "ERROR: Failed to create sqlite database! Exiting...\n"); #if USE_FORK scanning = 1; sqlite3_close(db); *scanner_pid = fork(); - open_db(); + open_db(&db); if( !(*scanner_pid) ) // child (scanner) process { start_scanner(); @@ -1102,10 +1105,9 @@ main(int argc, char * * argv) LIST_INIT(&upnphttphead); - if( (i = open_db()) == 0 ) - { + i = open_db(NULL); + if( i == 0 ) updateID = sql_get_int_field(db, "SELECT UPDATE_ID from SETTINGS"); - } check_db(db, i, &scanner_pid); signal(SIGCHLD, &sigchld); #ifdef HAVE_INOTIFY diff --git a/tagutils/tagutils-wav.c b/tagutils/tagutils-wav.c index e9f6c20..a183c92 100644 --- a/tagutils/tagutils-wav.c +++ b/tagutils/tagutils-wav.c @@ -204,7 +204,7 @@ _get_wavtags(char *filename, struct song_metadata *psong) p += taglen + 8; off += taglen + 8; /* Handle some common WAV file malformations */ - while (*p == '\0') { + while (*p == '\0' && off < len) { p++; off++; }