問題のメモリリークは治ったものの
「memory still reachable」が数件残ってしまった
見ると、原因箇所は printf
それも単純に変数を表示しているだけのところ
下のコードの4行目と5行目のprintf
1 2 3 4 5 6 7 8 9 10 |
void print(void) { printf("%s ", (code1 + code2).c_str()); printf("%4d try %4d win", count, wincount); printf(" (%3.0f%%)" , (0 < count) ? ((float)wincount / (float)count * 100.0f) : 0.0f); printf(", profit %+7.2f " , profitBuy + profitSell); printf("(%+7.3f %+7.3f)" , profitBuy, profitSell); printf(", Ave %7.3f" , (0 == count ) ? 0.0f : (profitBuy + profitSell) / (money_t)count * curGain); printf(", score %8s" , score.c_str()); printf("\n"); } |
エラー扱いでもないし、計算自体に影響はないけれど
ゴミが残るのは気持ち悪い
Valgrindのバグかなぁ
と思って検索したところ
結構、困っている人が多い様子
Cygwinでの計算結果も、正常に戻ったことだし
Merbericksの対応は試験的、ということなので
これ以上追わないことに
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
/usr/local/bin/valgrind --dsymutil=yes --leak-check=full --show-leak-kinds=all ./Trade2SignalsSim -method 1 -dir ../data -period 30 --last `date +%Y%m%d` ==84263== Memcheck, a memory error detector ==84263== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==84263== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info ==84263== Command: ./Trade2SignalsSim -method 1 -dir ../data -period 30 --last 20140816 ==84263== ==84263== WARNING: Support on MacOS 10.8/10.9 is experimental and mostly broken. ==84263== WARNING: Expect incorrect results, assertions and crashes. ==84263== WARNING: In particular, Memcheck on 32-bit programs will fail to ==84263== WARNING: detect any errors associated with heap-allocated data. ==84263== ... snip(プログラム出力) ... ==84263== ==84263== HEAP SUMMARY: ==84263== in use at exit: 29,436 bytes in 380 blocks ==84263== total heap usage: 1,432,114 allocs, 1,431,734 frees, 379,615,028 bytes allocated ==84263== ==84263== 32 bytes in 1 blocks are still reachable in loss record 31 of 81 ==84263== at 0x6DEB: malloc (in /usr/local/Cellar/valgrind/3.9.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so) ==84263== by 0x248AB0: __Balloc_D2A (in /usr/lib/system/libsystem_c.dylib) ==84263== by 0x245BE3: __rv_alloc_D2A (in /usr/lib/system/libsystem_c.dylib) ==84263== by 0x245C04: __nrv_alloc_D2A (in /usr/lib/system/libsystem_c.dylib) ==84263== by 0x245EB1: __dtoa (in /usr/lib/system/libsystem_c.dylib) ==84263== by 0x26D8A9: __vfprintf (in /usr/lib/system/libsystem_c.dylib) ==84263== by 0x2942DA: __v2printf (in /usr/lib/system/libsystem_c.dylib) ==84263== by 0x2946AF: __xvprintf (in /usr/lib/system/libsystem_c.dylib) ==84263== by 0x26BB29: vfprintf_l (in /usr/lib/system/libsystem_c.dylib) ==84263== by 0x26996F: printf (in /usr/lib/system/libsystem_c.dylib) ==84263== by 0x10000551C: Trade::Profit::print() (Trade.h:93) ==84263== by 0x100003A94: main (vector:1417) ==84263== |