]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mood.c
Merge topic branch t/afs-ls-a into master
[paraslash.git] / mood.c
diff --git a/mood.c b/mood.c
index 804fb57667563461229d5b9e37aa8a16c6320b67..b4d50c88e73533c69e7473c072e3aaef1c196d99 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -134,6 +134,8 @@ static void destroy_mood(struct mood_instance *m)
        if (!m)
                return;
        mp_shutdown(m->parser_context);
+       if (m->score_table)
+               score_close(m->score_table);
        free(m->name);
        free(m);
 }
@@ -531,6 +533,8 @@ static char *get_statistics(struct mood_instance *m, int64_t sse)
        unsigned n = m->stats.num;
        int mean_days, sigma_days;
 
+       if (n == 0)
+               return make_message("no admissible files\n");
        mean_days = (sse - m->stats.last_played_sum / n) / 3600 / 24;
        sigma_days = int_sqrt(m->stats.last_played_qd / n) / 3600 / 24;
        return make_message(
@@ -638,12 +642,6 @@ int mood_load(const char *mood_name, struct mood_instance **result, char **msg)
        }
        clock_get_realtime(&rnow);
        compute_correction_factors(rnow.tv_sec, &aa.m->stats);
-       if (aa.m->stats.num == 0) {
-               if (msg)
-                       *msg = make_message("no admissible files\n");
-               ret = 0;
-               goto out;
-       }
        if (result)
                score_open(&aa.m->score_table);
        for (i = 0; i < aa.m->stats.num; i++) {
@@ -665,9 +663,10 @@ int mood_load(const char *mood_name, struct mood_instance **result, char **msg)
                mood_unload(NULL);
                current_mood = aa.m;
        }
+       ret = 1;
 out:
        free(aa.array);
-       if (ret < 0)
+       if (ret <= 0) /* error, or no admissible files */
                destroy_mood(aa.m);
        return ret;
 }