summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-10-30 17:46:57 -0400
committerKonstantin Käfer <mail@kkaefer.com>2014-10-30 17:47:34 -0400
commit80366bc61586aea427fd39c1569a3f51a13eb8e2 (patch)
treeafef4bea17232714ef13246b583bdf9f000850e3 /src
parent19556009043d58dec3c96a5da6b962c6dcf249e9 (diff)
downloadqtlocation-mapboxgl-80366bc61586aea427fd39c1569a3f51a13eb8e2.tar.gz
allow providing a callback to uv_messenger_stop to prevent mismatched new/free
Diffstat (limited to 'src')
-rw-r--r--src/storage/file_source.cpp6
-rw-r--r--src/util/uv-messenger.c9
-rw-r--r--src/util/uv-worker.c6
3 files changed, 15 insertions, 6 deletions
diff --git a/src/storage/file_source.cpp b/src/storage/file_source.cpp
index 70b4abe4c7..a67f57dac4 100644
--- a/src/storage/file_source.cpp
+++ b/src/storage/file_source.cpp
@@ -23,9 +23,9 @@ FileSource::FileSource(uv_loop_t *loop_, const std::string &path)
FileSource::~FileSource() {
assert(thread_id == uv_thread_self());
- uv_messenger_stop(queue);
- // NOTE: We don't need to delete the messenger since it will be deleted by the
- // uv_messenger_stop() function.
+ uv_messenger_stop(queue, [](uv_messenger_t *msgr) {
+ delete msgr;
+ });
util::ptr<BaseRequest> req;
diff --git a/src/util/uv-messenger.c b/src/util/uv-messenger.c
index bfa1565768..935b6f1c41 100644
--- a/src/util/uv-messenger.c
+++ b/src/util/uv-messenger.c
@@ -2,6 +2,7 @@
#include <mbgl/util/queue.h>
#include <stdlib.h>
+#include <assert.h>
typedef struct {
void *data;
@@ -46,6 +47,7 @@ int uv_messenger_init(uv_loop_t *loop, uv_messenger_t *msgr, uv_messenger_cb cal
}
msgr->callback = callback;
+ msgr->stop_callback = NULL;
QUEUE_INIT(&msgr->queue);
@@ -73,9 +75,12 @@ void uv_messenger_unref(uv_messenger_t *msgr) {
}
void uv__messenger_stop_callback(uv_handle_t *handle) {
- free((uv_messenger_t *)handle->data);
+ uv_messenger_t *msgr = (uv_messenger_t *)handle->data;
+ msgr->stop_callback(msgr);
}
-void uv_messenger_stop(uv_messenger_t *msgr) {
+void uv_messenger_stop(uv_messenger_t *msgr, uv_messenger_stop_cb stop_callback) {
+ assert(!msgr->stop_callback);
+ msgr->stop_callback = stop_callback;
uv_close((uv_handle_t *)&msgr->async, uv__messenger_stop_callback);
}
diff --git a/src/util/uv-worker.c b/src/util/uv-worker.c
index 8b0cc6dda7..d2aa908019 100644
--- a/src/util/uv-worker.c
+++ b/src/util/uv-worker.c
@@ -18,6 +18,10 @@ struct uv__worker_thread_s {
uv_thread_t thread;
};
+void uv__worker_free_messenger(uv_messenger_t *msgr) {
+ free(msgr);
+}
+
void uv__worker_thread_finished(uv__worker_thread_t *worker_thread) {
uv_worker_t *worker = worker_thread->worker;
@@ -35,7 +39,7 @@ void uv__worker_thread_finished(uv__worker_thread_t *worker_thread) {
worker->count--;
if (worker->count == 0) {
uv_chan_destroy(&worker->chan);
- uv_messenger_stop(worker->msgr);
+ uv_messenger_stop(worker->msgr, uv__worker_free_messenger);
if (worker->close_cb) {
worker->close_cb(worker);
}