1 Star 0 Fork 32

fantaotao1/gazelle

forked from src-openEuler/gazelle 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0241-drop-netbuf-in-read_lwip_data-to-fix-mem-overflow.patch 2.37 KB
一键复制 编辑 原始数据 按行查看 历史
jinag12 提交于 2023-06-06 20:37 . revert cleancode series patches
From 3939d1baef23269bfd89d616979df4caf02801ca Mon Sep 17 00:00:00 2001
From: kircher <majun65@huawei.com>
Date: Sat, 27 May 2023 20:26:02 +0800
Subject: [PATCH] drop netbuf in read_lwip_data to fix mem overflow
---
src/lstack/core/lstack_lwip.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/src/lstack/core/lstack_lwip.c b/src/lstack/core/lstack_lwip.c
index 805ac82..f12bfdb 100644
--- a/src/lstack/core/lstack_lwip.c
+++ b/src/lstack/core/lstack_lwip.c
@@ -743,7 +743,6 @@ ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, u8_t apiflags)
uint32_t data_count = rte_ring_count(sock->conn->recvmbox->ring);
uint32_t read_num = LWIP_MIN(free_count, data_count);
struct pbuf *pbufs[SOCK_RECV_RING_SIZE];
- struct netbuf *netbufs[SOCK_RECV_RING_SIZE];
uint32_t read_count = 0;
ssize_t recv_len = 0;
@@ -751,10 +750,7 @@ ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, u8_t apiflags)
err_t err = ERR_OK;
if (NETCONN_IS_UDP(sock)) {
- err = netconn_recv_udp_raw_netbuf_flags(sock->conn, &netbufs[i], apiflags);
- pbufs[i] = netbufs[i]->p;
- pbufs[i]->addr = netbufs[i]->addr;
- pbufs[i]->port = netbufs[i]->port;
+ err = netconn_recv_udp_raw_pbuf_flags(sock->conn, &pbufs[i], apiflags);
} else {
err = netconn_recv_tcp_pbuf_flags(sock->conn, &pbufs[i], apiflags);
}
@@ -776,14 +772,9 @@ ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, u8_t apiflags)
}
uint32_t enqueue_num = gazelle_ring_sp_enqueue(sock->recv_ring, (void **)pbufs, read_count);
- if (NETCONN_IS_UDP(sock)) {
- for (uint32_t i = 0; i < read_count; i++) {
- memp_free(MEMP_NETBUF, netbufs[i]);
- }
- }
for (uint32_t i = enqueue_num; i < read_count; i++) {
if (NETCONN_IS_UDP(sock)) {
- netbuf_delete(netbufs[i]);
+ pbuf_free(pbufs[i]);
} else {
/* update receive window */
tcp_recved(sock->conn->pcb.tcp, pbufs[i]->tot_len);
@@ -1104,7 +1095,7 @@ ssize_t read_stack_data(int32_t fd, void *buf, size_t len, int32_t flags, struct
del_data_in_event(sock);
}
- if (addr && addrlen) {
+ if (pbuf && addr && addrlen) {
lwip_sock_make_addr(sock->conn, &(pbuf->addr), pbuf->port, addr, addrlen);
}
--
2.23.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fantaotao1/gazelle.git
git@gitee.com:fantaotao1/gazelle.git
fantaotao1
gazelle
gazelle
master

搜索帮助