次の内容は、プログラムを準備し、Discover を使用して計測を行い、それを実行して、検出したメモリーアクセスエラーに関するレポートを生成する例です。この例は初期化されていないデータにアクセスする単純なプログラムを使用します。
% cat test_UMR.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
// UMR: accessing uninitialized data
int *p = (int*) malloc(sizeof(int));
printf("*p = %d\n", *p);
free(p);
}
% cc -g -02 test_UMR.c
% a.out
*p = 131464
% discover -w - a.out
% a.out
ERROR (UMR): accessing uninitialized data from address 0x50010 (4 bytes) at:
main() + 0x54 <test_UMR.c:7>
4: {
5: // UMR: accessing uninitialized data
6: int *p = (int*) malloc(sizeof(int));
7:=> printf(**p = %d\n", *p);
8: free(p);
9: }
_start() + 0x108
block at 0x50010 (4 bytes long) was allocated at:
malloc() + 0x220
main() + 0x1c <test_UMR.c:6>
3: int main()
4: {
5: // UMR: accessing uninitialized data
6:=> int *p = (int*) malloc(sizeof(int));
7: printf(**p = %d\n", *p);
8: free(p);
9: }
_start() + 0x108
*p = 327704
**************** Discover Memory Report *****************
No allocated memory left on program exit.
DISCOVER SUMMARY:
unique errors : 1 (1 total, 0 filtered)
unique warnings : 0 (0 total, 0 filtered)
FILTERS: type=ML:func=_rt_boot:depth=*; type=*:func__f90_esfw:depth=*;
type=ML:func=__f90_ssfw:depth=*;
Discover 出力は、初期化されていないメモリーが使用された場所、およびそのメモリーが割り当てられた場所を、結果の概要とともに示します。