update: pass const string to update_enqueue()
Duplicate the path string within update.c, do not expect an allocated string as parameter.
This commit is contained in:
@@ -1018,12 +1018,12 @@ handle_playlistmove(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
|||||||
static enum command_return
|
static enum command_return
|
||||||
handle_update(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
handle_update(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *path = NULL;
|
const char *path = NULL;
|
||||||
unsigned ret;
|
unsigned ret;
|
||||||
|
|
||||||
assert(argc <= 2);
|
assert(argc <= 2);
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
path = g_strdup(argv[1]);
|
path = argv[1];
|
||||||
|
|
||||||
ret = update_enqueue(path);
|
ret = update_enqueue(path);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
|
18
src/update.c
18
src/update.c
@@ -790,7 +790,8 @@ static void * update_task(void *_path)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spawn_update_task(char *path)
|
static void
|
||||||
|
spawn_update_task(const char *path)
|
||||||
{
|
{
|
||||||
GError *e = NULL;
|
GError *e = NULL;
|
||||||
|
|
||||||
@@ -798,15 +799,18 @@ static void spawn_update_task(char *path)
|
|||||||
|
|
||||||
progress = UPDATE_PROGRESS_RUNNING;
|
progress = UPDATE_PROGRESS_RUNNING;
|
||||||
modified = false;
|
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);
|
g_error("Failed to spawn update task: %s", e->message);
|
||||||
|
|
||||||
if (++update_task_id > update_task_id_max)
|
if (++update_task_id > update_task_id_max)
|
||||||
update_task_id = 1;
|
update_task_id = 1;
|
||||||
g_debug("spawned thread for update job id %i", update_task_id);
|
g_debug("spawned thread for update job id %i", update_task_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
update_enqueue(char *path)
|
update_enqueue(const char *path)
|
||||||
{
|
{
|
||||||
assert(g_thread_self() == main_task);
|
assert(g_thread_self() == main_task);
|
||||||
|
|
||||||
@@ -816,17 +820,16 @@ update_enqueue(char *path)
|
|||||||
if (progress != UPDATE_PROGRESS_IDLE) {
|
if (progress != UPDATE_PROGRESS_IDLE) {
|
||||||
unsigned next_task_id;
|
unsigned next_task_id;
|
||||||
|
|
||||||
if (update_paths_nr == G_N_ELEMENTS(update_paths)) {
|
if (update_paths_nr == G_N_ELEMENTS(update_paths))
|
||||||
g_free(path);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
assert(update_paths_nr < G_N_ELEMENTS(update_paths));
|
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;
|
next_task_id = update_task_id + update_paths_nr;
|
||||||
|
|
||||||
return next_task_id > update_task_id_max ? 1 : next_task_id;
|
return next_task_id > update_task_id_max ? 1 : next_task_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn_update_task(path);
|
spawn_update_task(path);
|
||||||
|
|
||||||
idle_add(IDLE_UPDATE);
|
idle_add(IDLE_UPDATE);
|
||||||
@@ -884,6 +887,7 @@ static void update_finished_event(void)
|
|||||||
memmove(&update_paths[0], &update_paths[1],
|
memmove(&update_paths[0], &update_paths[1],
|
||||||
--update_paths_nr * sizeof(char *));
|
--update_paths_nr * sizeof(char *));
|
||||||
spawn_update_task(path);
|
spawn_update_task(path);
|
||||||
|
g_free(path);
|
||||||
} else {
|
} else {
|
||||||
progress = UPDATE_PROGRESS_IDLE;
|
progress = UPDATE_PROGRESS_IDLE;
|
||||||
|
|
||||||
|
12
src/update.h
12
src/update.h
@@ -27,12 +27,14 @@ void update_global_finish(void);
|
|||||||
unsigned
|
unsigned
|
||||||
isUpdatingDB(void);
|
isUpdatingDB(void);
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* returns the positive update job ID on success,
|
* Add this path to the database update queue.
|
||||||
* returns 0 if busy
|
*
|
||||||
* @path will be freed by this function and should not be reused
|
* @param path a path to update; if NULL or an empty string,
|
||||||
|
* the whole music directory is updated
|
||||||
|
* @return the job id, or 0 on error
|
||||||
*/
|
*/
|
||||||
unsigned
|
unsigned
|
||||||
update_enqueue(char *path);
|
update_enqueue(const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user