Bugfix: memory and thread-deleting problems
[monky] / src / mpd.c
index 24770db..ec929b7 100644 (file)
--- a/src/mpd.c
+++ b/src/mpd.c
@@ -81,9 +81,7 @@ int mpd_set_port(const char *port)
 void init_mpd(void)
 {
        if (!(refcount++))      /* first client */
-               memset(&mpd_info, 0, sizeof(struct mpd_s));
-
-       refcount++;
+               memset(&mpd_info, 0, sizeof(mpd_info));
 }
 
 struct mpd_s *mpd_get_info(void)
@@ -115,23 +113,24 @@ void free_mpd(void)
 
 static void *update_mpd_thread(void *) __attribute__((noreturn));
 
-void update_mpd(void)
+int update_mpd(void)
 {
        int interval;
        static timed_thread *thread = NULL;
 
        if (thread)
-               return;
+               return 0;
 
        interval = info.music_player_interval * 1000000;
        thread = timed_thread_create(&update_mpd_thread, &thread, interval);
        if (!thread) {
                NORM_ERR("Failed to create MPD timed thread");
-               return;
+               return 0;
        }
        timed_thread_register(thread, &thread);
        if (timed_thread_run(thread))
                NORM_ERR("Failed to run MPD timed thread");
+       return 0;
 }
 
 /* stringMAXdup dups at most text_buffer_size bytes */