aboutsummaryrefslogtreecommitdiffstats
path: root/src/update.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-09-24 21:39:43 +0200
committerMax Kellermann <max@duempel.org>2009-09-24 21:39:43 +0200
commitb0e1a3d34c9720db7acd244fa54321b3c2c982c6 (patch)
tree5515b8a62059ea34e70c5c362710284b1fae9af9 /src/update.c
parent1cc4914b246b861035519818f27de9876285b4d1 (diff)
downloadmpd-b0e1a3d34c9720db7acd244fa54321b3c2c982c6.tar.gz
mpd-b0e1a3d34c9720db7acd244fa54321b3c2c982c6.tar.xz
mpd-b0e1a3d34c9720db7acd244fa54321b3c2c982c6.zip
update: pass const string to update_enqueue()
Duplicate the path string within update.c, do not expect an allocated string as parameter.
Diffstat (limited to 'src/update.c')
-rw-r--r--src/update.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/update.c b/src/update.c
index 67258e82a..a85f883c6 100644
--- a/src/update.c
+++ b/src/update.c
@@ -790,7 +790,8 @@ static void * update_task(void *_path)
return NULL;
}
-static void spawn_update_task(char *path)
+static void
+spawn_update_task(const char *path)
{
GError *e = NULL;
@@ -798,15 +799,18 @@ static void spawn_update_task(char *path)
progress = UPDATE_PROGRESS_RUNNING;
modified = false;
- if (!(update_thr = g_thread_create(update_task, path, TRUE, &e)))
+
+ update_thr = g_thread_create(update_task, g_strdup(path), TRUE, &e);
+ if (update_thr == NULL)
g_error("Failed to spawn update task: %s", e->message);
+
if (++update_task_id > update_task_id_max)
update_task_id = 1;
g_debug("spawned thread for update job id %i", update_task_id);
}
unsigned
-update_enqueue(char *path)
+update_enqueue(const char *path)
{
assert(g_thread_self() == main_task);
@@ -816,17 +820,16 @@ update_enqueue(char *path)
if (progress != UPDATE_PROGRESS_IDLE) {
unsigned next_task_id;
- if (update_paths_nr == G_N_ELEMENTS(update_paths)) {
- g_free(path);
+ if (update_paths_nr == G_N_ELEMENTS(update_paths))
return 0;
- }
assert(update_paths_nr < G_N_ELEMENTS(update_paths));
- update_paths[update_paths_nr++] = path;
+ update_paths[update_paths_nr++] = g_strdup(path);
next_task_id = update_task_id + update_paths_nr;
return next_task_id > update_task_id_max ? 1 : next_task_id;
}
+
spawn_update_task(path);
idle_add(IDLE_UPDATE);
@@ -884,6 +887,7 @@ static void update_finished_event(void)
memmove(&update_paths[0], &update_paths[1],
--update_paths_nr * sizeof(char *));
spawn_update_task(path);
+ g_free(path);
} else {
progress = UPDATE_PROGRESS_IDLE;