Free memory

This commit is contained in:
zvon 2020-05-29 20:53:27 +02:00
parent b0450da800
commit 4ff070b731
5 changed files with 32 additions and 3 deletions

View File

@ -228,3 +228,10 @@ bool dbusPlaying( DBusConnection *conn, const char *player ) {
free( status );
return ret;
}
void dbusFreePlyaers( char **dbus_players ) {
for( char **player = dbus_players; *player; ++player ) {
free( *player );
}
free( dbus_players );
}

View File

@ -15,5 +15,6 @@ void dbusPrev( DBusConnection *conn, const char *player );
void dbusStop( DBusConnection *conn, const char *player );
bool dbusRunning( DBusConnection *conn, const char *player );
bool dbusPlaying( DBusConnection *conn, const char *player );
void dbusFreePlyaers( char **dbus_players );
#endif

11
main.c
View File

@ -79,6 +79,7 @@ int main( int argc, char **argv ) {
printMeta( &song );
}
}
freeSong( &song );
}
if( requests & RUNNING_FLAG ) {
@ -121,9 +122,13 @@ int main( int argc, char **argv ) {
}
}
free( dbus_players );
dbusDisconnect( dbus_connection );
mpdDisconnect( mpd_connection );
if( sources & DBUS_FLAG ) {
dbusFreePlyaers( dbus_players );
dbusDisconnect( dbus_connection );
}
if( sources & MPD_FLAG ) {
mpdDisconnect( mpd_connection );
}
return ret;
}

View File

@ -22,3 +22,18 @@ void printMeta( struct song_metadata *song ) {
printf( "ART: %s\n", song->art_uri );
}
}
void freeSong( struct song_metadata *song ) {
free( (void*)song->art_uri );
song->art_uri = NULL;
free( (void*)song->file );
song->file = NULL;
free( (void*)song->year );
song->year = NULL;
free( (void*)song->artist );
song->artist = NULL;
free( (void*)song->album );
song->album = NULL;
free( (void*)song->title );
song->title = NULL;
}

View File

@ -12,5 +12,6 @@ struct song_metadata {
void printSong( struct song_metadata *song );
void printMeta( struct song_metadata *song );
void freeSong( struct song_metadata *song );
#endif