C_and_CPP 板


LINE

开发平台(Platform): (Ex: Win10, Linux, ...) RP1 + Raspbian 编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出) gcc 4.9.2 编译参数:-Wall -pedantic -O3 -std=gnu11 -lpthread 额外使用到的函数库(Library Used): (Ex: OpenGL, ...) pthread 问题(Question): 正在练习写multithread的code 使用gcc编译会有Warning(用clang不会) 跑起来也没问题 可是valgrind显示有memary leakage (我没用malloc) 不知道如何改善 预期的正确结果(Expected Output): 无memory leak 错误结果(Wrong Output): gcc的Warning如下: atomic.c:30:9: warning: right-hand operand of comma expression has no effect [-Wunused-value] ++acnt; ^ atomic.c:32:9: warning: right-hand operand of comma expression has no effect [-Wunused-value] --acnt; ^ Valgrind在RPi的Error如下: ==1083== Memcheck, a memory error detector ==1083== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==1083== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==1083== Command: ./atomic ==1083== 0th Time: One 0th Time: Three 0th Time: 1th Time: Three 1th Time: One Two 2th Time: One 2th Time: Three 3th Time: One 1th Time: Two 4th Time: One 3th Time: Three 2th Time: Two 5th Time: One 4th Time: Three 3th Time: Two 6th Time: One 5th Time: Three 4th Time: Two 7th Time: One 6th Time: Three 5th Time: Two 8th Time: One 7th Time: Three 6th Time: Two 9th Time: One 8th Time: Three 7th Time: Two 9th Time: Three 8th Time: Two 9th Time: Two ==1083== Thread 2: ==1083== Invalid read of size 4 ==1083== at 0x40197E0: strlen (strlen.S:76) ==1083== by 0x400B6DB: _dl_new_object (dl-object.c:157) ==1083== by 0x4005A5B: _dl_map_object_from_fd (dl-load.c:1059) ==1083== by 0x4008D93: _dl_map_object (dl-load.c:2605) ==1083== by 0x40143F7: dl_open_worker (dl-open.c:235) ==1083== by 0x400FE93: _dl_catch_error (dl-error.c:187) ==1083== by 0x4013D47: _dl_open (dl-open.c:661) ==1083== by 0x4999DEB: do_dlopen (dl-libc.c:87) ==1083== by 0x400FE93: _dl_catch_error (dl-error.c:187) ==1083== by 0x4999ED3: dlerror_run (dl-libc.c:46) ==1083== by 0x4999F53: __libc_dlopen_mode (dl-libc.c:163) ==1083== by 0x4879A7F: pthread_cancel_init (unwind-forcedunwind.c:46) ==1083== Address 0x51d2274 is 36 bytes inside a block of size 39 alloc'd ==1083== at 0x4833970: malloc (vg_replace_malloc.c:263) ==1083== by 0x400579B: local_strdup (dl-load.c:162) ==1083== by 0x4008FEB: _dl_map_object (dl-load.c:2509) ==1083== by 0x40143F7: dl_open_worker (dl-open.c:235) ==1083== by 0x400FE93: _dl_catch_error (dl-error.c:187) ==1083== by 0x4013D47: _dl_open (dl-open.c:661) ==1083== by 0x4999DEB: do_dlopen (dl-libc.c:87) ==1083== by 0x400FE93: _dl_catch_error (dl-error.c:187) ==1083== by 0x4999ED3: dlerror_run (dl-libc.c:46) ==1083== by 0x4999F53: __libc_dlopen_mode (dl-libc.c:163) ==1083== by 0x4879A7F: pthread_cancel_init (unwind-forcedunwind.c:46) ==1083== by 0x4879BAF: _Unwind_ForcedUnwind (unwind-forcedunwind.c:145) ==1083== ==1083== ==1083== HEAP SUMMARY: ==1083== in use at exit: 948 bytes in 4 blocks ==1083== total heap usage: 8 allocs, 4 frees, 1,384 bytes allocated ==1083== ==1083== LEAK SUMMARY: ==1083== definitely lost: 0 bytes in 0 blocks ==1083== indirectly lost: 0 bytes in 0 blocks ==1083== possibly lost: 0 bytes in 0 blocks ==1083== still reachable: 948 bytes in 4 blocks ==1083== suppressed: 0 bytes in 0 blocks ==1083== Rerun with --leak-check=full to see details of leaked memory ==1083== ==1083== For counts of detected and suppressed errors, rerun with: -v ==1083== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) 程式码(Code):(请善用置底文网页, 记得排版) https://gist.github.com/gnitnaw/84939b400ba3391cec188e5376dedaf9 补充说明(Supplement): 同样的code我拿来笔电跑(core*4 + Lubuntu 16.04 + gcc 5.4 + Valgrind-3.11.0) 在Valgrind是没有错误的,不过gcc的warning还是在。 改用clang就没有warning了 --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 86.209.148.33
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1476879857.A.E31.html ※ 编辑: wtchen (86.209.148.33), 10/19/2016 20:44:53
1F:推 longlongint: 不知道欸 试试看改用 -O2 ? 10/19 20:45
2F:→ wtchen: 用过了,一样有Error 10/19 20:48
3F:→ wtchen: 如果是RPi+clang去编译,valgrind根本不让我run... 10/19 20:50
4F:→ wtchen: 看了一下gcc的bugzilla,似乎gcc6才修掉这bug 10/19 20:59
5F:→ wtchen: 顺便请教,以本case来说需要用volatile修饰i2c_stat? 10/19 21:41
6F:推 Bencrie: 那个错误叫存取违规不叫 memory leak 10/19 22:04







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Gossiping站内搜寻

TOP