V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  YsHaNg  ›  全部回复第 1 页 / 共 40 页
回复总数  798
1  2  3  4  5  6  7  8  9  10 ... 40  
android 不支持 pd 吗 私有协议非行业标准就忽略掉 一个 usb-c 就可以搞定所有 iPhone 换 15 可以简化成两条线
4 天前
回复了 xaoflysho 创建的主题 NAS 想问问大伙 NAS 备份照片的方案
@myderr 群晖 photos 本身也无感备份 live 后台不划走卡片锁屏接电源 几万张照片可能几周完成
@JingXiao 多少年前空格键不就行吗
6 天前
回复了 vksss 创建的主题 Apple iPhone Wifi-Calling 无法开启,出现以下错误
你们为啥都执着于这玩意 家里 Wi-Fi 不好移动信号好的角落反而劣化通话质量
7 天前
回复了 balddonkey1 创建的主题 iOS Google Photo 后台总被杀掉,没法备份
7 天前
回复了 schellong 创建的主题 求职 寻一份远程工作
@kingfighters 不啊 我就开个早会 改个参数 build 一跑十几个小时 该玩啥玩啥
10 天前
回复了 xiaobai332 创建的主题 软件 passkey 是否该存到密码管理器中?
@ysc3839 不用 手机就行
10 天前
回复了 david101 创建的主题 iPad 吐槽 iPad mini
你想要的是 stage manager 任意应用都能小窗
15 天前
回复了 dododada 创建的主题 程序员 算法工程师的工程能力问题
你们现在一说算法就全 ML 了 搞得我也不知道该怎么说好 做量子逻辑门优化 toffoli 的算不算做算法的? 我们还有搞 PQC 加密协议只在纸上白板上工作的算不算?
16 天前
回复了 honeygeek 创建的主题 NAS 群晖 920+的 M2 接口问题
@honeygeek 记得内存单颗粒不要大于 1Gb
18 天前
回复了 zhouyin 创建的主题 美酒与美食 每餐吃土司
@xu455255849 白人饭上瘾患者真的觉得这很好吃 还有夹熟牛肉片 夹 tuna 拌蛋黄酱 省时 开火炒菜什么的经常做饭 1 小时吃饭 5 分钟
21 天前
回复了 ShikiSuen 创建的主题 Apple 买苹果产品,建议抢首发
v2er 日常发疯
用各种 debit credit card 没用过微信支付 支付宝一年用一次 你确定世界上只有中国吗
22 天前
回复了 Tumblr 创建的主题 NAS 想买个 NAS,群晖 DS923+可?
@Salvin 有公网 qc 是直连 跑满上行和 ddns 速度没差别
22 天前
回复了 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.
25 天前
回复了 Dandelion2333 创建的主题 长沙 大龄长沙女生找对象
@hanlin85 年薪 40 还在长沙那不就是减分项了
1  2  3  4  5  6  7  8  9  10 ... 40  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2446 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 47ms · UTC 13:43 · PVG 21:43 · LAX 06:43 · JFK 09:43
Developed with CodeLauncher
♥ Do have faith in what you're doing.