|
9 | 9 | * 2018-04-12 chenyong add client implement |
10 | 10 | * 2018-08-17 chenyong multiple client support |
11 | 11 | * 2021-03-17 Meco Man fix a buf of leaking memory |
| 12 | + * 2021-07-14 Sszl fix a buf of leaking memory |
12 | 13 | */ |
13 | 14 |
|
14 | 15 | #include <at.h> |
@@ -571,30 +572,19 @@ int at_obj_set_urc_table(at_client_t client, const struct at_urc *urc_table, rt_ |
571 | 572 | } |
572 | 573 | else |
573 | 574 | { |
574 | | - struct at_urc_table *old_urc_table = RT_NULL; |
575 | | - size_t old_table_size = client->urc_table_size * sizeof(struct at_urc_table); |
576 | | - |
577 | | - old_urc_table = (struct at_urc_table *) rt_malloc(old_table_size); |
578 | | - if (old_urc_table == RT_NULL) |
579 | | - { |
580 | | - return -RT_ENOMEM; |
581 | | - } |
582 | | - rt_memcpy(old_urc_table, client->urc_table, old_table_size); |
| 575 | + struct at_urc_table *new_urc_table = RT_NULL; |
583 | 576 |
|
584 | 577 | /* realloc urc table space */ |
585 | | - client->urc_table = (struct at_urc_table *) rt_realloc(client->urc_table, |
586 | | - old_table_size + sizeof(struct at_urc_table)); |
587 | | - if (client->urc_table == RT_NULL) |
| 578 | + 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)); |
| 579 | + if (new_urc_table == RT_NULL) |
588 | 580 | { |
589 | | - rt_free(old_urc_table); |
590 | 581 | return -RT_ENOMEM; |
591 | 582 | } |
592 | | - rt_memcpy(client->urc_table, old_urc_table, old_table_size); |
| 583 | + client->urc_table = new_urc_table; |
593 | 584 | client->urc_table[client->urc_table_size].urc = urc_table; |
594 | 585 | client->urc_table[client->urc_table_size].urc_size = table_sz; |
595 | 586 | client->urc_table_size++; |
596 | 587 |
|
597 | | - rt_free(old_urc_table); |
598 | 588 | } |
599 | 589 |
|
600 | 590 | return RT_EOK; |
|
0 commit comments