diff --git a/lib/misc/lws-struct-sqlite.c b/lib/misc/lws-struct-sqlite.c index b0599681d..327537c15 100644 --- a/lib/misc/lws-struct-sqlite.c +++ b/lib/misc/lws-struct-sqlite.c @@ -185,6 +185,9 @@ lws_struct_sq3_deserialize(sqlite3 *pdb, const char *filter, const char *order, lws_struct_args_t a; int limit = _limit < 0 ? -_limit : _limit; + if (!order) + order = "_lws_idx"; + memset(&a, 0, sizeof(a)); a.cb_arg = o; /* lws_dll2_owner tracking query result objects */ a.map_st[0] = schema->child_map; @@ -199,8 +202,8 @@ lws_struct_sq3_deserialize(sqlite3 *pdb, const char *filter, const char *order, (unsigned long long)start, filter ? filter : ""); lws_snprintf(s, sizeof(s) - 1, "select * " - "from %s %s order by _lws_idx%s %slimit %d;", - schema->colname, where, order ? order : "", + "from %s %s order by %s %slimit %d;", + schema->colname, where, order, _limit < 0 ? "desc " : "", limit); if (sqlite3_exec(pdb, s, lws_struct_sq3_deser_cb, &a, NULL) != SQLITE_OK) { diff --git a/lib/misc/threadpool/threadpool.c b/lib/misc/threadpool/threadpool.c index f12d980ce..e5394fbe7 100644 --- a/lib/misc/threadpool/threadpool.c +++ b/lib/misc/threadpool/threadpool.c @@ -265,25 +265,28 @@ __lws_threadpool_reap(struct lws_threadpool_task *task) /* remove the task from the done queue */ - c = &tp->task_done_head; + if (tp) { + c = &tp->task_done_head; - while (*c) { - if ((*c) == task) { - t = *c; - *c = t->task_queue_next; - t->task_queue_next = NULL; - tp->done_queue_depth--; + while (*c) { + if ((*c) == task) { + t = *c; + *c = t->task_queue_next; + t->task_queue_next = NULL; + tp->done_queue_depth--; - lwsl_thread("%s: tp %s: reaped task wsi %p\n", __func__, - tp->name, task_to_wsi(task)); + lwsl_thread("%s: tp %s: reaped task wsi %p\n", __func__, + tp->name, task_to_wsi(task)); - break; + break; + } + c = &(*c)->task_queue_next; } - c = &(*c)->task_queue_next; - } - if (!t) - lwsl_err("%s: task %p not in done queue\n", __func__, task); + if (!t) + lwsl_err("%s: task %p not in done queue\n", __func__, task); + } else + lwsl_err("%s: task->tp NULL already\n", __func__); /* call the task's cleanup and delete the task itself */