From bce37e7bd85b5a2777f1dcebc999b598c35f3fcb Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Fri, 24 Mar 2017 17:39:29 +0900 Subject: [PATCH] Fix callback disapeared bug For locally declared callback function, screen_connector_toolkit_add should copy and store callback functions. Change-Id: I14ac550d5f062e03315046bedd0b69649972255f Signed-off-by: Hyunho Kang --- .../src/screen_connector_toolkit.c | 23 ++++++++++++++++++++-- .../src/screen_connector_toolkit_evas.c | 22 ++++++++++----------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/screen_connector_watcher/src/screen_connector_toolkit.c b/screen_connector_watcher/src/screen_connector_toolkit.c index b9f31e4..910d73f 100644 --- a/screen_connector_watcher/src/screen_connector_toolkit.c +++ b/screen_connector_watcher/src/screen_connector_toolkit.c @@ -247,17 +247,26 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_create_handle(cha screen_connector_toolkit_ops *ops, void *data) { screen_connector_toolkit_h toolkit_h = NULL; + screen_connector_toolkit_ops *ops_copy; + + ops_copy = (screen_connector_toolkit_ops *)calloc(1, sizeof(screen_connector_toolkit_ops)); + if (ops_copy == NULL) { + LOGE("ops_copy calloc fail"); + return NULL; + } + memcpy(ops_copy, ops, sizeof(screen_connector_toolkit_ops)); toolkit_h = (screen_connector_toolkit_h)calloc(1, sizeof(struct _screen_connector_toolkit_h)); if (toolkit_h == NULL) { LOGE("toolkit_h calloc fail"); + free(ops_copy); return NULL; } toolkit_h->surface_id = surface_id; toolkit_h->appid = strdup(id); toolkit_h->instance_id = strdup(id); toolkit_h->data = data; - toolkit_h->ops = ops; + toolkit_h->ops = ops_copy; return toolkit_h; } @@ -267,6 +276,7 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add(screen_connec { screen_connector_toolkit_h toolkit_h = NULL; screen_connector_type_h type_h = NULL; + screen_connector_toolkit_ops *ops_copy; if (id == NULL || ops == NULL) { LOGE("Invalid param"); @@ -279,14 +289,23 @@ EXPORT_API screen_connector_toolkit_h screen_connector_toolkit_add(screen_connec return NULL; } + ops_copy = (screen_connector_toolkit_ops *)calloc(1, sizeof(screen_connector_toolkit_ops)); + if (ops_copy == NULL) { + LOGE("ops_copy calloc fail"); + return NULL; + } + memcpy(ops_copy, ops, sizeof(screen_connector_toolkit_ops)); + toolkit_h = (screen_connector_toolkit_h)calloc(1, sizeof(struct _screen_connector_toolkit_h)); if (toolkit_h == NULL) { LOGE("toolkit_h calloc fail"); + free(ops_copy); return NULL; } + toolkit_h->instance_id = strdup(id); toolkit_h->data = data; - toolkit_h->ops = ops; + toolkit_h->ops = ops_copy; toolkit_h->type_h = type_h; if (type_h->toolkit_table == NULL) diff --git a/screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c b/screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c index da88b31..5a78547 100644 --- a/screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c +++ b/screen_connector_watcher_evas/src/screen_connector_toolkit_evas.c @@ -586,7 +586,7 @@ EXPORT_API screen_connector_toolkit_evas_h screen_connector_toolkit_evas_add(scr { screen_connector_toolkit_evas_h handle; screen_connector_toolkit_evas_ops *evas_ops; - screen_connector_toolkit_ops *toolkit_ops; + screen_connector_toolkit_ops toolkit_ops; screen_connector_type_evas_h type_h; int int_type = type; @@ -596,10 +596,9 @@ EXPORT_API screen_connector_toolkit_evas_h screen_connector_toolkit_evas_add(scr return NULL; } - toolkit_ops = (screen_connector_toolkit_ops *)calloc(1, sizeof(screen_connector_toolkit_ops)); - toolkit_ops->added_cb = __toolkit_added_cb; - toolkit_ops->updated_cb = __toolkit_update_cb; - toolkit_ops->removed_cb = __toolkit_removed_cb; + toolkit_ops.added_cb = __toolkit_added_cb; + toolkit_ops.updated_cb = __toolkit_update_cb; + toolkit_ops.removed_cb = __toolkit_removed_cb; evas_ops = (screen_connector_toolkit_evas_ops *)calloc(1, sizeof(screen_connector_toolkit_evas_ops)); if (evas_ops == NULL) { @@ -618,7 +617,7 @@ EXPORT_API screen_connector_toolkit_evas_h screen_connector_toolkit_evas_add(scr handle->ops = evas_ops; handle->data = data; handle->type_h = type_h; - handle->toolkit_h = screen_connector_toolkit_add(toolkit_ops, id, type, handle); + handle->toolkit_h = screen_connector_toolkit_add(&toolkit_ops, id, type, handle); return handle; } @@ -834,7 +833,7 @@ EXPORT_API screen_connector_toolkit_evas_h screen_connector_toolkit_evas_add_by_ { screen_connector_toolkit_evas_h handle; screen_connector_toolkit_evas_ops *evas_ops; - screen_connector_toolkit_ops *toolkit_ops; + screen_connector_toolkit_ops toolkit_ops; screen_connector_type_evas_h type_h; char rid_str[32]; @@ -844,10 +843,9 @@ EXPORT_API screen_connector_toolkit_evas_h screen_connector_toolkit_evas_add_by_ return NULL; } - toolkit_ops = (screen_connector_toolkit_ops *)calloc(1, sizeof(screen_connector_toolkit_ops)); - toolkit_ops->added_cb = __toolkit_added_cb; - toolkit_ops->updated_cb = __toolkit_update_cb; - toolkit_ops->removed_cb = __toolkit_removed_cb; + toolkit_ops.added_cb = __toolkit_added_cb; + toolkit_ops.updated_cb = __toolkit_update_cb; + toolkit_ops.removed_cb = __toolkit_removed_cb; evas_ops = (screen_connector_toolkit_evas_ops *)calloc(1, sizeof(screen_connector_toolkit_evas_ops)); if (evas_ops == NULL) { @@ -868,7 +866,7 @@ EXPORT_API screen_connector_toolkit_evas_h screen_connector_toolkit_evas_add_by_ handle->type_h = type_h; snprintf(rid_str, sizeof(rid_str), "%d", res_id); - handle->toolkit_h = screen_connector_toolkit_create_handle(rid_str, res_id, toolkit_ops, handle); + handle->toolkit_h = screen_connector_toolkit_create_handle(rid_str, res_id, &toolkit_ops, handle); screen_connector_toolkit_redirect_surface(handle->toolkit_h); return handle; -- 2.7.4