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/m.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燈, 水草

請輸入看板名稱,例如:Soft_Job站內搜尋

TOP