2

これは、アドレスサニタイザーで構築されたプログラムを実行しているときに表示され、興味をそそられました。

gperftools ソース コードには、次の関数が含まれています。

void MallocExtension::Register(MallocExtension* implementation) {
  InitModule();
  // When running under valgrind, our custom malloc is replaced with
  // valgrind's one and malloc extensions will not work.  (Note:
  // callers should be responsible for checking that they are the
  // malloc that is really being run, before calling Register.  This
  // is just here as an extra sanity check.)
  if (!RunningOnValgrind()) {
    current_instance = implementation;
  }
}

以下のようにInitModule定義して

static void InitModule() {
  if (current_instance != NULL) {
    return;
  }
  current_instance = new MallocExtension; // pointless?
#ifndef NO_HEAP_CHECK
  HeapLeakChecker::IgnoreObject(current_instance);
#endif
}

私たちのアドレス サニタイザー (もちろん valgrind ではありません) は、MallocExtensionオブジェクトのメモリ リークについて文句を言います。どうやら、それは正しいです。しかし、そもそもなぜこの割り当てがあるのでしょうか?

独自のメモリ アロケータを開発している人々が、このような些細な間違いを犯すとは思いません。valgrind に対する明示的なチェックもあります。では、割り当ての目的は何ですか?

4

1 に答える 1