Skip to content
Extraits de code Groupes Projets
Vérifiée Valider f2cfd88d rédigé par Kubat's avatar Kubat
Parcourir les fichiers

FIX: Free the filter uri pointer

Before the pointer was freed by the launching thread, thus the called
thread would still use the location after being freed by another thread...
parent a1932e36
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!177Add the query to the `update` command to filter karas to update
Pipeline #2481 réussi
Ce commit fait partie de la requête de fusion !177. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
......@@ -192,5 +192,6 @@ lkt_uri_match_kara_metadata(const struct lkt_uri *uri, const struct kara_metadat
case URI_PLAYLIST: return database_plt_contais_kara(db, uri->value, kara_id);
case URI_LANGUAGE: return STR_MATCH((const char *)uri->value, kara_mdt->language);
}
LOG_ERROR("URI", "Found an unusual uri type: %d", uri->type);
LOG_UNREACHABLE;
}
......@@ -564,24 +564,26 @@ ___handle_deleted_kara(lkt_db *db, struct queue *queue)
* poll which contains the function pointer and other informations that are not
* needed here. The `___args` is a pointer to a `update_worker_argument`
* structure allocated on the heap (because execution is assyncronous) and is
* consumed by the worker thread, e.g. will be freed by it. */
* consumed by the worker thread, e.g. will be freed by it. The ``filter_uri`
* passed in the `___args` pointer is also moved in the `___worker_update`
* function and will be freed by it. */
PRIVATE_FUNCTION void *
___worker_update(void UNUSED *worker, void *___args)
{
struct update_worker_argument *arguments = (struct update_worker_argument *)(___args);
struct module_repo_internal *repo = arguments->repo;
struct lkt_uri *filter_uri = arguments->filter_uri;
char *json = NULL;
free(___args);
lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATING, LKT_DB_UPDATING_PROGRESS);
DO_WITH_LOCK(repo->mtx, end_no_lock, repo->updating &= REPO_UPDATE_KARA);
char *json;
LOG_INFO("REPO", "Download kara list from %s", repo->name);
if (___json_dl(repo->get_all_json, &json)) {
LOG_ERROR("REPO", "Failed to get json, possibly no internet connexion or repo is down");
return NULL;
goto error;
}
int ret = ___handle_got_json(repo->db, repo, json, filter_uri, false);
......@@ -591,17 +593,24 @@ ___worker_update(void UNUSED *worker, void *___args)
if (ret != 2) {
LOG_INFO("REPO", "No interrupt requested, don't skip delete kara operation");
___handle_deleted_kara(repo->db, repo->queue);
} else {
LOG_WARN("REPO", "Handle json was interrupt, skip delete kara operation");
}
LOG_WARN_IF(ret == 2, "REPO", "Handle json was interrupt, skip delete kara operation");
LOG_INFO("REPO", "Finished to deal with deleted kara");
database_updated(repo->db);
error: // Failed to download the json from the repo
DO_WITH_LOCK(repo->mtx, end_no_lock, repo->updating &= (~REPO_UPDATE_KARA));
lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATING, LKT_DB_UPDATING_FINISHED);
free(filter_uri);
return NULL;
end_no_lock:
end_no_lock: // Failed to take a lock
LOG_ERROR("REPO", "Failed to take a lock, the REPO_UPDATE_KARA flag might still be "
"present even if no update is in progress. You need to restart "
"lektord to be able to update!");
lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATING, LKT_DB_UPDATING_FINISHED);
free(filter_uri);
return NULL;
}
......@@ -941,40 +950,35 @@ mod_update(va_list *va)
va_list copy;
struct module_repo_internal **repo;
struct lkt_uri *uri_ptr;
struct lkt_uri *uri = LKT_ALLOC_STRUCT(lkt_uri);
va_copy(copy, *va);
repo = (struct module_repo_internal **)va_arg(copy, void **);
uri_ptr = (struct lkt_uri *)va_arg(copy, struct lkt_uri *);
int ret = 0;
/* Copy the URI pointer before doing anything else. Necessary because when
* the thread will be launched, the stack allocated thing passed to the repo
* module could no longer be the correct thing. */
memcpy(uri, uri_ptr, sizeof(struct lkt_uri));
GOTO_IF(pthread_mutex_lock(&(*repo)->mtx), "Failed to lock", end_no_lock);
DO_WITH_LOCK((*repo)->mtx, end_no_lock, {
if ((*repo)->updating & REPO_UPDATE_KARA) {
LOG_WARN("REPO", "Already updating");
goto end;
}
} else {
(*repo)->updating &= REPO_UPDATE_KARA;
struct update_worker_argument *args = LKT_ALLOC_STRUCT(update_worker_argument);
args->repo = *repo;
args->filter_uri = uri;
args->filter_uri = LKT_ALLOC_STRUCT(lkt_uri);
memcpy(args->filter_uri, uri_ptr, sizeof(struct lkt_uri));
/* `args` and `args->filter_uri` are moved, is owner is now
* `___worker_update`. That function will free those pointers. */
if (worker_pool_push(&(*repo)->workers, ___worker_update, (void *)args)) {
LOG_ERROR("REPO", "Out of memory");
ret = 1;
goto end;
} else {
LOG_INFO("REPO", "Update started (update)");
}
}
});
LOG_INFO("REPO", "Update started (update)");
end:
GOTO_IF(pthread_mutex_unlock(&(*repo)->mtx), "Failed to unlock", end_no_lock);
end_no_lock:
va_end(copy);
free(uri);
return ret;
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter