diff options
| author | guo <[email protected]> | 2021-07-27 09:59:56 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-27 09:59:56 +0800 |
| commit | 1f1547946604eb65ba1c414fb1ee514eed693a77 (patch) | |
| tree | 5f38531f0054e0d17ec53ad65d502406377bfebc | |
| parent | 8663e8739e7107a0df73631d3153dd6813292873 (diff) | |
| parent | bf88963a3ec85ce6da013e4cd1c59ec5041d29e1 (diff) | |
Merge pull request #4743 from sszllzss/at_client-rt_realloc_iss
[components][net][at]修改at_obj_set_urc_table函数重新分配内存可能导致内存泄漏问题
| -rw-r--r-- | components/net/at/src/at_client.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/components/net/at/src/at_client.c b/components/net/at/src/at_client.c index 7904c24d92..948020f4cf 100644 --- a/components/net/at/src/at_client.c +++ b/components/net/at/src/at_client.c @@ -9,6 +9,7 @@ * 2018-04-12 chenyong add client implement * 2018-08-17 chenyong multiple client support * 2021-03-17 Meco Man fix a buf of leaking memory + * 2021-07-14 Sszl fix a buf of leaking memory */ #include <at.h> @@ -571,30 +572,19 @@ int at_obj_set_urc_table(at_client_t client, const struct at_urc *urc_table, rt_ } else { - struct at_urc_table *old_urc_table = RT_NULL; - size_t old_table_size = client->urc_table_size * sizeof(struct at_urc_table); - - old_urc_table = (struct at_urc_table *) rt_malloc(old_table_size); - if (old_urc_table == RT_NULL) - { - return -RT_ENOMEM; - } - rt_memcpy(old_urc_table, client->urc_table, old_table_size); + struct at_urc_table *new_urc_table = RT_NULL; /* realloc urc table space */ - client->urc_table = (struct at_urc_table *) rt_realloc(client->urc_table, - old_table_size + sizeof(struct at_urc_table)); - if (client->urc_table == RT_NULL) + new_urc_table = (struct at_urc_table *) rt_realloc(client->urc_table,client->urc_table_size * sizeof(struct at_urc_table) + sizeof(struct at_urc_table)); + if (new_urc_table == RT_NULL) { - rt_free(old_urc_table); return -RT_ENOMEM; } - rt_memcpy(client->urc_table, old_urc_table, old_table_size); + client->urc_table = new_urc_table; client->urc_table[client->urc_table_size].urc = urc_table; client->urc_table[client->urc_table_size].urc_size = table_sz; client->urc_table_size++; - rt_free(old_urc_table); } return RT_EOK; |
