From 50a97669cf62b443aec80ac2a88297db817bf105 Mon Sep 17 00:00:00 2001 From: BernardXiong Date: Tue, 26 Mar 2019 13:49:18 +0000 Subject: [PATCH 1/2] [Kernel] Add object re-initialization check. --- src/object.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/object.c b/src/object.c index 70b9a5c04e..050bb17757 100644 --- a/src/object.c +++ b/src/object.c @@ -251,6 +251,9 @@ void rt_object_init(struct rt_object *object, /* initialize object's parameters */ + /* check object type to avoid re-initialization */ + RT_ASSERT(object->type != (type | RT_Object_Class_Static)); + /* set object type to static */ object->type = type | RT_Object_Class_Static; From 4d3b4abfebc0a4a98c814e66cee807918dcad53d Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Tue, 2 Apr 2019 17:33:07 +0800 Subject: [PATCH 2/2] [Kernel] To check object re-initialization in the list --- src/object.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/object.c b/src/object.c index 050bb17757..e85737ce8f 100644 --- a/src/object.c +++ b/src/object.c @@ -240,6 +240,7 @@ void rt_object_init(struct rt_object *object, const char *name) { register rt_base_t temp; + struct rt_list_node *node = RT_NULL; struct rt_object_information *information; #ifdef RT_USING_MODULE struct rt_dlmodule *module = dlmodule_self(); @@ -249,14 +250,26 @@ void rt_object_init(struct rt_object *object, information = rt_object_get_information(type); RT_ASSERT(information != RT_NULL); - /* initialize object's parameters */ - /* check object type to avoid re-initialization */ - RT_ASSERT(object->type != (type | RT_Object_Class_Static)); + /* enter critical */ + rt_enter_critical(); + /* try to find object */ + for (node = information->object_list.next; + node != &(information->object_list); + node = node->next) + { + struct rt_object *obj; + + obj = rt_list_entry(node, struct rt_object, list); + RT_ASSERT(obj != object); + } + /* leave critical */ + rt_exit_critical(); + + /* initialize object's parameters */ /* set object type to static */ object->type = type | RT_Object_Class_Static; - /* copy name */ rt_strncpy(object->name, name, RT_NAME_MAX);