* Miscellaneous minor cleanups for string termination and unfreed memory at exit.

This commit is contained in:
Justin Maggard 2012-02-13 22:48:48 +00:00
parent 0687d8f6d8
commit 6fcd16985e
3 changed files with 32 additions and 40 deletions

View File

@ -211,8 +211,7 @@ getfriendlyname(char * buf, int len)
if( gethostname(hn, 256) == 0 ) if( gethostname(hn, 256) == 0 )
{ {
strncpy(buf, hn, len-1); strncpyt(buf, hn, len);
buf[len] = '\0';
dot = strchr(buf, '.'); dot = strchr(buf, '.');
if( dot ) if( dot )
*dot = '\0'; *dot = '\0';
@ -242,8 +241,7 @@ getfriendlyname(char * buf, int len)
key = strchr(val, ' '); key = strchr(val, ' ');
if( key ) if( key )
{ {
strncpy(modelnumber, key+1, MODELNUMBER_MAX_LEN); strncpyt(modelnumber, key+1, MODELNUMBER_MAX_LEN);
modelnumber[MODELNUMBER_MAX_LEN-1] = '\0';
*key = '\0'; *key = '\0';
} }
snprintf(modelname, MODELNAME_MAX_LEN, snprintf(modelname, MODELNAME_MAX_LEN,
@ -251,8 +249,7 @@ getfriendlyname(char * buf, int len)
} }
else if( strcmp(key, "serial") == 0 ) else if( strcmp(key, "serial") == 0 )
{ {
strncpy(serialnumber, val, SERIALNUMBER_MAX_LEN); strncpyt(serialnumber, val, SERIALNUMBER_MAX_LEN);
serialnumber[SERIALNUMBER_MAX_LEN-1] = '\0';
if( serialnumber[0] == '\0' ) if( serialnumber[0] == '\0' )
{ {
char mac_str[13]; char mac_str[13];
@ -344,8 +341,7 @@ init(int argc, char * * argv)
int verbose_flag = 0; int verbose_flag = 0;
int options_flag = 0; int options_flag = 0;
struct sigaction sa; struct sigaction sa;
/*const char * logfilename = 0;*/ const char * presurl = NULL;
const char * presurl = 0;
const char * optionsfile = "/etc/minidlna.conf"; const char * optionsfile = "/etc/minidlna.conf";
char mac_str[13]; char mac_str[13];
char * string, * word; char * string, * word;
@ -437,20 +433,16 @@ init(int argc, char * * argv)
runtime_vars.notify_interval = atoi(ary_options[i].value); runtime_vars.notify_interval = atoi(ary_options[i].value);
break; break;
case UPNPSERIAL: case UPNPSERIAL:
strncpy(serialnumber, ary_options[i].value, SERIALNUMBER_MAX_LEN); strncpyt(serialnumber, ary_options[i].value, SERIALNUMBER_MAX_LEN);
serialnumber[SERIALNUMBER_MAX_LEN-1] = '\0';
break; break;
case UPNPMODEL_NAME: case UPNPMODEL_NAME:
strncpy(modelname, ary_options[i].value, MODELNAME_MAX_LEN); strncpyt(modelname, ary_options[i].value, MODELNAME_MAX_LEN);
modelname[MODELNAME_MAX_LEN-1] = '\0';
break; break;
case UPNPMODEL_NUMBER: case UPNPMODEL_NUMBER:
strncpy(modelnumber, ary_options[i].value, MODELNUMBER_MAX_LEN); strncpyt(modelnumber, ary_options[i].value, MODELNUMBER_MAX_LEN);
modelnumber[MODELNUMBER_MAX_LEN-1] = '\0';
break; break;
case UPNPFRIENDLYNAME: case UPNPFRIENDLYNAME:
strncpy(friendly_name, ary_options[i].value, FRIENDLYNAME_MAX_LEN); strncpyt(friendly_name, ary_options[i].value, FRIENDLYNAME_MAX_LEN);
friendly_name[FRIENDLYNAME_MAX_LEN-1] = '\0';
break; break;
case UPNPMEDIADIR: case UPNPMEDIADIR:
type = ALL_MEDIA; type = ALL_MEDIA;
@ -535,7 +527,7 @@ init(int argc, char * * argv)
DPRINTF(E_FATAL, L_GENERAL, "Database path not accessible! [%s]\n", path); DPRINTF(E_FATAL, L_GENERAL, "Database path not accessible! [%s]\n", path);
break; break;
} }
strncpy(db_path, path, PATH_MAX); strncpyt(db_path, path, PATH_MAX);
break; break;
case UPNPLOGDIR: case UPNPLOGDIR:
path = realpath(ary_options[i].value, buf); path = realpath(ary_options[i].value, buf);
@ -547,7 +539,7 @@ init(int argc, char * * argv)
DPRINTF(E_FATAL, L_GENERAL, "Log path not accessible! [%s]\n", path); DPRINTF(E_FATAL, L_GENERAL, "Log path not accessible! [%s]\n", path);
break; break;
} }
strncpy(log_path, path, PATH_MAX); strncpyt(log_path, path, PATH_MAX);
break; break;
case UPNPINOTIFY: case UPNPINOTIFY:
if( (strcmp(ary_options[i].value, "yes") != 0) && !atoi(ary_options[i].value) ) if( (strcmp(ary_options[i].value, "yes") != 0) && !atoi(ary_options[i].value) )
@ -601,12 +593,12 @@ init(int argc, char * * argv)
if( log_path[0] == '\0' ) if( log_path[0] == '\0' )
{ {
if( db_path[0] == '\0' ) if( db_path[0] == '\0' )
strncpy(log_path, DEFAULT_LOG_PATH, PATH_MAX); strncpyt(log_path, DEFAULT_LOG_PATH, PATH_MAX);
else else
strncpy(log_path, db_path, PATH_MAX); strncpyt(log_path, db_path, PATH_MAX);
} }
if( db_path[0] == '\0' ) if( db_path[0] == '\0' )
strncpy(db_path, DEFAULT_DB_PATH, PATH_MAX); strncpyt(db_path, DEFAULT_DB_PATH, PATH_MAX);
/* command line arguments processing */ /* command line arguments processing */
for(i=1; i<argc; i++) for(i=1; i<argc; i++)
@ -630,21 +622,16 @@ init(int argc, char * * argv)
break; break;
case 's': case 's':
if(i+1 < argc) if(i+1 < argc)
strncpy(serialnumber, argv[++i], SERIALNUMBER_MAX_LEN); strncpyt(serialnumber, argv[++i], SERIALNUMBER_MAX_LEN);
else else
DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]);
serialnumber[SERIALNUMBER_MAX_LEN-1] = '\0';
break; break;
case 'm': case 'm':
if(i+1 < argc) if(i+1 < argc)
strncpy(modelnumber, argv[++i], MODELNUMBER_MAX_LEN); strncpyt(modelnumber, argv[++i], MODELNUMBER_MAX_LEN);
else else
DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]); DPRINTF(E_ERROR, L_GENERAL, "Option -%c takes one argument.\n", argv[i][1]);
modelnumber[MODELNUMBER_MAX_LEN-1] = '\0';
break; break;
/*case 'l':
logfilename = argv[++i];
break;*/
case 'p': case 'p':
if(i+1 < argc) if(i+1 < argc)
runtime_vars.port = atoi(argv[++i]); runtime_vars.port = atoi(argv[++i]);
@ -819,15 +806,9 @@ init(int argc, char * * argv)
/* presentation url */ /* presentation url */
if(presurl) if(presurl)
{ strncpyt(presentationurl, presurl, PRESENTATIONURL_MAX_LEN);
strncpy(presentationurl, presurl, PRESENTATIONURL_MAX_LEN);
presentationurl[PRESENTATIONURL_MAX_LEN-1] = '\0';
}
else else
{ strcpy(presentationurl, "/");
snprintf(presentationurl, PRESENTATIONURL_MAX_LEN,
"http://%s:%d/", lan_addr[0].str, runtime_vars.port);
}
/* set signal handler */ /* set signal handler */
memset(&sa, 0, sizeof(struct sigaction)); memset(&sa, 0, sizeof(struct sigaction));
@ -1270,6 +1251,8 @@ shutdown:
sql_exec(db, "UPDATE SETTINGS set UPDATE_ID = %u", updateID); sql_exec(db, "UPDATE SETTINGS set UPDATE_ID = %u", updateID);
sqlite3_close(db); sqlite3_close(db);
upnpevents_removeSubscribers();
media_path = media_dirs; media_path = media_dirs;
art_names = album_art_names; art_names = album_art_names;
while( media_path ) while( media_path )

View File

@ -194,6 +194,16 @@ upnpevents_removeSubscriber(const char * sid, int sidlen)
return -1; return -1;
} }
void
upnpevents_removeSubscribers(void)
{
struct subscriber * sub;
for(sub = subscriberlist.lh_first; sub != NULL; sub = subscriberlist.lh_first) {
upnpevents_removeSubscriber(sub->uuid, sizeof(sub->uuid));
}
}
/* notifies all subscribers of a SystemUpdateID change */ /* notifies all subscribers of a SystemUpdateID change */
void void
upnp_event_var_change_notify(enum subscriber_service_enum service) upnp_event_var_change_notify(enum subscriber_service_enum service)

View File

@ -61,11 +61,10 @@ upnpevents_addSubscriber(const char * eventurl,
const char * callback, int callbacklen, const char * callback, int callbacklen,
int timeout); int timeout);
int int upnpevents_removeSubscriber(const char * sid, int sidlen);
upnpevents_removeSubscriber(const char * sid, int sidlen); void upnpevents_removeSubscribers(void);
int int renewSubscription(const char * sid, int sidlen, int timeout);
renewSubscription(const char * sid, int sidlen, int timeout);
void upnpevents_selectfds(fd_set *readset, fd_set *writeset, int * max_fd); void upnpevents_selectfds(fd_set *readset, fd_set *writeset, int * max_fd);
void upnpevents_processfds(fd_set *readset, fd_set *writeset); void upnpevents_processfds(fd_set *readset, fd_set *writeset);