diff options
| author | chen zx <[email protected]> | 2021-08-06 17:05:50 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-06 17:05:50 +0800 |
| commit | b104bbc4f9d978209e898a6dfced53248e27e3d7 (patch) | |
| tree | c6852a2c6500e7d7e2902d8a63eac4e1774ae50a /components/net | |
| parent | eb29bb5318b2d4b0a3ff48ed906b72c074bcc17d (diff) | |
| parent | 054f6db3e651cb6e7340913e969f5656626b9e9a (diff) | |
Merge branch 'RT-Thread:master' into master
Diffstat (limited to 'components/net')
| -rw-r--r-- | components/net/at/at_socket/at_socket.c | 17 | ||||
| -rw-r--r-- | components/net/at/src/at_client.c | 20 | ||||
| -rw-r--r-- | components/net/lwip-1.4.1/src/lwipopts.h | 7 | ||||
| -rw-r--r-- | components/net/lwip-1.4.1/src/netif/ethernetif.c | 8 | ||||
| -rw-r--r-- | components/net/lwip-2.0.2/src/lwipopts.h | 11 | ||||
| -rw-r--r-- | components/net/lwip-2.0.2/src/netif/ethernetif.c | 8 | ||||
| -rw-r--r-- | components/net/lwip-2.0.3/src/lwipopts.h | 11 | ||||
| -rw-r--r-- | components/net/lwip-2.0.3/src/netif/ethernetif.c | 8 | ||||
| -rw-r--r-- | components/net/lwip-2.1.2/src/lwipopts.h | 11 | ||||
| -rw-r--r-- | components/net/lwip-2.1.2/src/netif/ethernetif.c | 8 | ||||
| -rw-r--r-- | components/net/sal_socket/include/socket/netdb.h | 2 |
11 files changed, 68 insertions, 43 deletions
diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index 973be0acf4..8215dd4417 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -13,6 +13,7 @@ #include <string.h> #include <ctype.h> #include <sys/time.h> +#include <sys/errno.h> #include <at_socket.h> #include <at_device.h> @@ -78,7 +79,7 @@ struct at_socket *at_get_socket(int socket) } /* get a block to the AT socket receive list*/ -static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) +static rt_err_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) { at_recv_pkt_t pkt = RT_NULL; @@ -86,7 +87,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) if (pkt == RT_NULL) { LOG_E("No memory for receive packet table!"); - return 0; + return -RT_ENOMEM; } pkt->bfsz_totle = length; @@ -95,7 +96,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) rt_slist_append(rlist, &pkt->list); - return length; + return RT_EOK; } /* delete and free all receive buffer list */ @@ -651,14 +652,20 @@ static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, con RT_ASSERT(event == AT_SOCKET_EVT_RECV); /* check the socket object status */ - if (sock->magic != AT_SOCKET_MAGIC) + if (sock->magic != AT_SOCKET_MAGIC || sock->state == AT_SOCKET_CLOSED) { + rt_free((void *)buff); return; } /* put receive buffer to receiver packet list */ rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER); - at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz); + if (at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz) != RT_EOK) + { + rt_free((void *)buff); + rt_mutex_release(sock->recv_lock); + return; + } rt_mutex_release(sock->recv_lock); rt_sem_release(sock->recv_notice); 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; diff --git a/components/net/lwip-1.4.1/src/lwipopts.h b/components/net/lwip-1.4.1/src/lwipopts.h index 0b7e092d6c..9148066d50 100644 --- a/components/net/lwip-1.4.1/src/lwipopts.h +++ b/components/net/lwip-1.4.1/src/lwipopts.h @@ -222,6 +222,13 @@ #define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) /* ---------- Memory options ---------- */ +#ifdef RT_USING_ASM_MEMCPY +#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len) +#else +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif /* RT_USING_ASM_MEMCPY */ +#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len) + #define MEM_ALIGNMENT 4 #define MEM_LIBC_MALLOC 1 diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 4565f5e528..40cd8fb6ef 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -201,14 +201,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, { return -RT_ERROR; } - rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); - rt_memcpy(&ina, &h->sin_addr, sizeof(ina)); + SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); + SMEMCPY(&ina, &h->sin_addr, sizeof(ina)); lwip_freeaddrinfo(res); if (inet_aton(inet_ntoa(ina), &target_addr) == 0) { return -RT_ERROR; } - rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); + SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) @@ -331,7 +331,7 @@ static int netdev_add(struct netif *lwip_netif) netdev->mtu = lwip_netif->mtu; netdev->ops = &lwip_netdev_ops; netdev->hwaddr_len = lwip_netif->hwaddr_len; - rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); + SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); netdev->ip_addr = lwip_netif->ip_addr; netdev->gw = lwip_netif->gw; netdev->netmask = lwip_netif->netmask; diff --git a/components/net/lwip-2.0.2/src/lwipopts.h b/components/net/lwip-2.0.2/src/lwipopts.h index d559684c02..fdfe1437b2 100644 --- a/components/net/lwip-2.0.2/src/lwipopts.h +++ b/components/net/lwip-2.0.2/src/lwipopts.h @@ -230,14 +230,21 @@ #define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) /* ---------- Memory options ---------- */ +#ifdef RT_USING_ASM_MEMCPY +#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len) +#else +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif /* RT_USING_ASM_MEMCPY */ +#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len) + #ifdef RT_LWIP_MEM_ALIGNMENT #define MEM_ALIGNMENT RT_LWIP_MEM_ALIGNMENT #else #define MEM_ALIGNMENT 4 #endif -#define MEMP_OVERFLOW_CHECK 1 //// -#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //// +#define MEMP_OVERFLOW_CHECK 1 +#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //#define MEM_LIBC_MALLOC 1 //#define MEM_USE_POOLS 1 //#define MEMP_USE_CUSTOM_POOLS 1 diff --git a/components/net/lwip-2.0.2/src/netif/ethernetif.c b/components/net/lwip-2.0.2/src/netif/ethernetif.c index 1c0f3ca9b2..0b1943fdff 100644 --- a/components/net/lwip-2.0.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.2/src/netif/ethernetif.c @@ -210,14 +210,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, { return -RT_ERROR; } - rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); - rt_memcpy(&ina, &h->sin_addr, sizeof(ina)); + SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); + SMEMCPY(&ina, &h->sin_addr, sizeof(ina)); lwip_freeaddrinfo(res); if (inet_aton(inet_ntoa(ina), &target_addr) == 0) { return -RT_ERROR; } - rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); + SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) @@ -340,7 +340,7 @@ static int netdev_add(struct netif *lwip_netif) netdev->mtu = lwip_netif->mtu; netdev->ops = &lwip_netdev_ops; netdev->hwaddr_len = lwip_netif->hwaddr_len; - rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); + SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); netdev->ip_addr = lwip_netif->ip_addr; netdev->gw = lwip_netif->gw; netdev->netmask = lwip_netif->netmask; diff --git a/components/net/lwip-2.0.3/src/lwipopts.h b/components/net/lwip-2.0.3/src/lwipopts.h index d559684c02..fdfe1437b2 100644 --- a/components/net/lwip-2.0.3/src/lwipopts.h +++ b/components/net/lwip-2.0.3/src/lwipopts.h @@ -230,14 +230,21 @@ #define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) /* ---------- Memory options ---------- */ +#ifdef RT_USING_ASM_MEMCPY +#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len) +#else +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif /* RT_USING_ASM_MEMCPY */ +#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len) + #ifdef RT_LWIP_MEM_ALIGNMENT #define MEM_ALIGNMENT RT_LWIP_MEM_ALIGNMENT #else #define MEM_ALIGNMENT 4 #endif -#define MEMP_OVERFLOW_CHECK 1 //// -#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //// +#define MEMP_OVERFLOW_CHECK 1 +#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //#define MEM_LIBC_MALLOC 1 //#define MEM_USE_POOLS 1 //#define MEMP_USE_CUSTOM_POOLS 1 diff --git a/components/net/lwip-2.0.3/src/netif/ethernetif.c b/components/net/lwip-2.0.3/src/netif/ethernetif.c index 1c0f3ca9b2..0b1943fdff 100644 --- a/components/net/lwip-2.0.3/src/netif/ethernetif.c +++ b/components/net/lwip-2.0.3/src/netif/ethernetif.c @@ -210,14 +210,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, { return -RT_ERROR; } - rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); - rt_memcpy(&ina, &h->sin_addr, sizeof(ina)); + SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); + SMEMCPY(&ina, &h->sin_addr, sizeof(ina)); lwip_freeaddrinfo(res); if (inet_aton(inet_ntoa(ina), &target_addr) == 0) { return -RT_ERROR; } - rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); + SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) @@ -340,7 +340,7 @@ static int netdev_add(struct netif *lwip_netif) netdev->mtu = lwip_netif->mtu; netdev->ops = &lwip_netdev_ops; netdev->hwaddr_len = lwip_netif->hwaddr_len; - rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); + SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); netdev->ip_addr = lwip_netif->ip_addr; netdev->gw = lwip_netif->gw; netdev->netmask = lwip_netif->netmask; diff --git a/components/net/lwip-2.1.2/src/lwipopts.h b/components/net/lwip-2.1.2/src/lwipopts.h index 2cd7cb023a..a964ab13ac 100644 --- a/components/net/lwip-2.1.2/src/lwipopts.h +++ b/components/net/lwip-2.1.2/src/lwipopts.h @@ -242,9 +242,16 @@ #endif /* ---------- Memory options ---------- */ +#ifdef RT_USING_ASM_MEMCPY +#define MEMCPY(dst,src,len) rt_memcpy(dst,src,len) +#else +#define MEMCPY(dst,src,len) memcpy(dst,src,len) +#endif /* RT_USING_ASM_MEMCPY */ +#define SMEMCPY(dst,src,len) MEMCPY(dst,src,len) + #define MEM_ALIGNMENT 4 -#define MEMP_OVERFLOW_CHECK 1 //// -#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //// +#define MEMP_OVERFLOW_CHECK 1 +#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1 //#define MEM_LIBC_MALLOC 1 //#define MEM_USE_POOLS 1 //#define MEMP_USE_CUSTOM_POOLS 1 diff --git a/components/net/lwip-2.1.2/src/netif/ethernetif.c b/components/net/lwip-2.1.2/src/netif/ethernetif.c index 81dd792f29..bd4db225ee 100644 --- a/components/net/lwip-2.1.2/src/netif/ethernetif.c +++ b/components/net/lwip-2.1.2/src/netif/ethernetif.c @@ -208,14 +208,14 @@ int lwip_netdev_ping(struct netdev *netif, const char *host, size_t data_len, { return -RT_ERROR; } - rt_memcpy(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); - rt_memcpy(&ina, &h->sin_addr, sizeof(ina)); + SMEMCPY(&h, &res->ai_addr, sizeof(struct sockaddr_in *)); + SMEMCPY(&ina, &h->sin_addr, sizeof(ina)); lwip_freeaddrinfo(res); if (inet_aton(inet_ntoa(ina), &target_addr) == 0) { return -RT_ERROR; } - rt_memcpy(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); + SMEMCPY(&(ping_resp->ip_addr), &target_addr, sizeof(ip_addr_t)); /* new a socket */ if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) @@ -338,7 +338,7 @@ static int netdev_add(struct netif *lwip_netif) netdev->mtu = lwip_netif->mtu; netdev->ops = &lwip_netdev_ops; netdev->hwaddr_len = lwip_netif->hwaddr_len; - rt_memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); + SMEMCPY(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len); netdev->ip_addr = lwip_netif->ip_addr; netdev->gw = lwip_netif->gw; netdev->netmask = lwip_netif->netmask; diff --git a/components/net/sal_socket/include/socket/netdb.h b/components/net/sal_socket/include/socket/netdb.h index 4783405022..9d54953681 100644 --- a/components/net/sal_socket/include/socket/netdb.h +++ b/components/net/sal_socket/include/socket/netdb.h @@ -6,7 +6,7 @@ * Change Logs: * Date Author Notes * 2015-02-17 Bernard First version - * 2108-05-24 ChenYong Add socket abstraction layer + * 2018-05-24 ChenYong Add socket abstraction layer */ #ifndef NETDB_H__ |
