From: Changyeon Lee Date: Thu, 7 Jan 2021 08:02:25 +0000 (+0900) Subject: surface: use magic number for checking valid of surface X-Git-Tag: accepted/tizen/unified/20210115.125753~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=a79a1d9ad916dc3d9f71180af0196c1a85647b52;p=platform%2Fcore%2Fuifw%2Flibtbm.git surface: use magic number for checking valid of surface Change-Id: If6c987d276c97d2a21ba38c76d0a01e66cbdcfe5 --- diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index cc789db..da0997d 100644 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -210,6 +210,8 @@ struct _tbm_bufmgr { * */ struct _tbm_surface { + unsigned int magic; /* tbm surface magic number */ + tbm_bufmgr bufmgr; /* tbm buffer manager */ tbm_surface_info_s info; /* tbm surface information */ diff --git a/src/tbm_surface_internal.c b/src/tbm_surface_internal.c index cdafc92..a682fd1 100644 --- a/src/tbm_surface_internal.c +++ b/src/tbm_surface_internal.c @@ -41,6 +41,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#define TBM_SURFACE_MAGIC 0xBF021234 + static tbm_bufmgr g_surface_bufmgr; static pthread_mutex_t tbm_surface_lock = PTHREAD_MUTEX_INITIALIZER; void _tbm_surface_mutex_unlock(void); @@ -250,25 +252,30 @@ _deinit_surface_bufmgr(void) /* LCOV_EXCL_STOP */ static int -_tbm_surface_internal_is_valid(tbm_surface_h surface) +_tbm_surface_internal_magic_check(tbm_surface_h surface) { - tbm_surface_h old_data = NULL; + if (surface->magic != TBM_SURFACE_MAGIC) + return 0; - TBM_RETURN_VAL_IF_FAIL(g_surface_bufmgr, 0); - TBM_RETURN_VAL_IF_FAIL(surface, 0); + return 1; +} - if (!LIST_IS_EMPTY(&g_surface_bufmgr->surf_list)) { - LIST_FOR_EACH_ENTRY(old_data, &g_surface_bufmgr->surf_list, item_link) { - if (old_data == surface) - return 1; - } +static int +_tbm_surface_internal_is_valid(tbm_surface_h surface) +{ + if (!surface) { + _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER); + TBM_ERR("error: No valid tbm_surface is NULL\n"); + return 0; } - _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER); - - TBM_ERR("error: No valid tbm_surface(%p)\n", surface); + if (!_tbm_surface_internal_magic_check(surface)) { + _tbm_set_last_result(TBM_ERROR_INVALID_PARAMETER); + TBM_ERR("error: No valid tbm_surface(%p)\n", surface); + return 0; + } - return 0; + return 1; } static int @@ -353,6 +360,7 @@ _tbm_surface_internal_destroy(tbm_surface_h surface) } LIST_DEL(&surface->item_link); + surface->magic = 0; free(surface); surface = NULL; @@ -752,6 +760,7 @@ tbm_surface_internal_create_with_flags(int width, int height, /* LCOV_EXCL_STOP */ } + surf->magic = TBM_SURFACE_MAGIC; surf->bufmgr = bufmgr; surf->info.width = width; surf->info.height = height; @@ -998,6 +1007,7 @@ tbm_surface_internal_create_with_bos(tbm_surface_info_s *info, /* LCOV_EXCL_STOP */ } + surf->magic = TBM_SURFACE_MAGIC; surf->bufmgr = bufmgr; surf->info.width = info->width; surf->info.height = info->height;