YsHaNg 最近的时间轴更新
YsHaNg
ONLINE

YsHaNg

V2EX 第 548994 号会员,加入于 2021-06-22 04:28:19 +08:00
今日活跃度排名 10252
YsHaNg 最近回复了
5 小时 2 分钟前
回复了 zhouyin 创建的主题 美酒与美食 每餐吃土司
@xu455255849 白人饭上瘾患者真的觉得这很好吃 还有夹熟牛肉片 夹 tuna 拌蛋黄酱 省时 开火炒菜什么的经常做饭 1 小时吃饭 5 分钟
2 天前
回复了 gsy20050126 创建的主题 Apple 买苹果产品,建议抢首发
v2er 日常发疯
用各种 debit credit card 没用过微信支付 支付宝一年用一次 你确定世界上只有中国吗
3 天前
回复了 Tumblr 创建的主题 NAS 想买个 NAS,群晖 DS923+可?
@Salvin 有公网 qc 是直连 跑满上行和 ddns 速度没差别
3 天前
回复了 laters 创建的主题 Visual Studio Code vscode 远程开发好用吗 ?
很好用
@albert0yyyy RAII+smart ptr 多用 auto 会让生活好很多
@Tifou 2 年 3 家😂 3 倍
TL;DR 扔给 GPT 了
Yes, there are several memory leaks in the provided code. Let's go through them:

1. In the loop where you receive messages via the socket, you allocate memory for `receiveData` using `cJSON_Print`, but you don't free it. You should free it after you're done using it.

2. Similarly, you create a `cJSON` object using `cJSON_Parse`, but you don't free it using `cJSON_Delete`.

3. You allocate memory for `json_str` using `cJSON_Print`, but you don't free it after sending it over the socket.

4. You allocate memory for `input` and `output` inside the loop, but you don't free them before the next iteration of the loop. This can lead to memory leaks if `input` or `output` fail to initialize.

To fix these memory leaks:

- Free `receiveData` after its use with `SAFE_DELETE(receiveData)`.

- Delete the `cjson_receive` object using `cJSON_Delete` after its use.

- Free `json_str` after sending it over the socket.

- Delete `input` and `output` objects at the end of each iteration of the loop before reinitializing them.

Here's how you can do it:

```cpp
SAFE_DELETE(receiveData);
cJSON_Delete(cjson_receive);
SAFE_DELETE(json_str);
SAFE_DELETE(input);
SAFE_DELETE(output);
```

Place these lines at appropriate locations in your code to ensure memory allocated dynamically is properly deallocated.
6 天前
回复了 Dandelion2333 创建的主题 长沙 大龄长沙女生找对象
@hanlin85 年薪 40 还在长沙那不就是减分项了
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1048 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 20:01 · PVG 04:01 · LAX 13:01 · JFK 16:01
Developed with CodeLauncher
♥ Do have faith in what you're doing.