From 57eb1c5a805fc6d545b26f0d076fe9ff08802144 Mon Sep 17 00:00:00 2001 From: sszlbg Date: Sat, 29 May 2021 13:23:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9at=5Fobj=5Fset=5Furc=5Fta?= =?UTF-8?q?ble=E5=87=BD=E6=95=B0=E9=87=8D=E6=96=B0=E5=88=86=E9=85=8D?= =?UTF-8?q?=E5=86=85=E5=AD=98=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/net/at/src/at_client.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/components/net/at/src/at_client.c b/components/net/at/src/at_client.c index a613ea1435..37892eee2c 100644 --- a/components/net/at/src/at_client.c +++ b/components/net/at/src/at_client.c @@ -8,7 +8,8 @@ * 2018-03-30 chenyong first version * 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-03-17 Meco Man fix a buf of leaking memory + * 2021-05-29 Sszl fix a buf of leaking memory */ #include @@ -562,29 +563,18 @@ 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); + /* realloc urc table space */ + old_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 (old_urc_table == RT_NULL) { return -RT_ENOMEM; } - rt_memcpy(old_urc_table, client->urc_table, old_table_size); - /* 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) - { - rt_free(old_urc_table); - return -RT_ENOMEM; - } - rt_memcpy(client->urc_table, old_urc_table, old_table_size); 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; From 88d4faf68735948d6310e2d2271d576c5de254a0 Mon Sep 17 00:00:00 2001 From: sszl Date: Wed, 14 Jul 2021 09:22:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0old=5Furc=5Ftable?= =?UTF-8?q?=E4=B8=BAnew=5Furc=5Ftable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/net/at/src/at_client.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/net/at/src/at_client.c b/components/net/at/src/at_client.c index 37892eee2c..f40d7698a7 100644 --- a/components/net/at/src/at_client.c +++ b/components/net/at/src/at_client.c @@ -9,7 +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-05-29 Sszl fix a buf of leaking memory + * 2021-07-14 Sszl fix a buf of leaking memory */ #include @@ -562,15 +562,15 @@ 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; + struct at_urc_table *new_urc_table = RT_NULL; /* realloc urc table space */ - old_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 (old_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) { return -RT_ENOMEM; } - + 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++;