diff options
| author | heyuanjie <[email protected]> | 2018-05-02 09:47:57 +0800 |
|---|---|---|
| committer | heyuanjie <[email protected]> | 2018-05-02 09:47:57 +0800 |
| commit | 313920126ba1bfaa7fb833860536c03f78f436fb (patch) | |
| tree | 54b011f26104ae478323cc33709e9f9622023662 /src | |
| parent | aa86f7f7bb78443780a71486a66c2f339243484f (diff) | |
| parent | 795f9873ccd1fc71497d5c2d96fb870ea17fe67b (diff) | |
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into imx1050
Diffstat (limited to 'src')
| -rw-r--r-- | src/memheap.c | 8 | ||||
| -rw-r--r-- | src/mempool.c | 4 | ||||
| -rw-r--r-- | src/module.c | 11 |
3 files changed, 20 insertions, 3 deletions
diff --git a/src/memheap.c b/src/memheap.c index dcd9114620..7317ebdbab 100644 --- a/src/memheap.c +++ b/src/memheap.c @@ -659,6 +659,12 @@ void *rt_realloc(void *rmem, rt_size_t newsize) if (rmem == RT_NULL) return rt_malloc(newsize); + if (newsize == 0) + { + rt_free(rmem); + return RT_NULL; + } + /* get old memory item */ header_ptr = (struct rt_memheap_item *) ((rt_uint8_t *)rmem - RT_MEMHEAP_SIZE); @@ -678,6 +684,8 @@ void *rt_realloc(void *rmem, rt_size_t newsize) rt_memcpy(new_ptr, rmem, oldsize); else rt_memcpy(new_ptr, rmem, newsize); + + rt_free(rmem); } } diff --git a/src/mempool.c b/src/mempool.c index 3de2d5fd7f..5d80d66533 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -95,7 +95,7 @@ rt_err_t rt_mp_init(struct rt_mempool *mp, rt_size_t block_size) { rt_uint8_t *block_ptr; - register rt_base_t offset; + register rt_size_t offset; /* parameter check */ RT_ASSERT(mp != RT_NULL); @@ -200,7 +200,7 @@ rt_mp_t rt_mp_create(const char *name, { rt_uint8_t *block_ptr; struct rt_mempool *mp; - register rt_base_t offset; + register rt_size_t offset; RT_DEBUG_NOT_IN_INTERRUPT; diff --git a/src/module.c b/src/module.c index b9801558dc..b48fae9418 100644 --- a/src/module.c +++ b/src/module.c @@ -636,7 +636,7 @@ static struct rt_module *_load_shared_object(const char *name, length = rt_strlen((const char *)(strtab + symtab[i].st_name)) + 1; module->symtab[count].addr = - (void *)(module->module_space + symtab[i].st_value); + (void *)(module->module_space + symtab[i].st_value - module->vstart_addr); module->symtab[count].name = rt_malloc(length); rt_memset((void *)module->symtab[count].name, 0, length); rt_memcpy((void *)module->symtab[count].name, @@ -1501,6 +1501,7 @@ rt_err_t rt_module_unload(rt_module_t module) { struct rt_object *object; struct rt_list_node *list; + rt_bool_t mdelete = RT_TRUE; RT_DEBUG_NOT_IN_INTERRUPT; @@ -1511,6 +1512,9 @@ rt_err_t rt_module_unload(rt_module_t module) rt_enter_critical(); if (!(module->parent.flag & RT_MODULE_FLAG_WITHOUTENTRY)) { + /* delete module in main thread destroy */ + mdelete = RT_FALSE; + /* delete all sub-threads */ list = &module->module_object[RT_Object_Class_Thread].object_list; while (list->next != list) @@ -1543,6 +1547,11 @@ rt_err_t rt_module_unload(rt_module_t module) } #endif + if (mdelete == RT_TRUE) + { + rt_module_destroy(module); + } + return RT_EOK; } |
