代码清单 4. 请记住在 SIGSEGV 处理程序中调用 muntrace()。

#include <stdio.h>
#include <stdlib.h>
#include <mcheck.h>
#include <signal.h>

void handler(int s) {
  muntrace();
  abort();
}

int main() {
  char *ptr;

  signal(SIGSEGV, handler);
  mtrace();
  ptr = malloc(10);
  free(ptr);
  free(ptr);

}
© . All rights reserved.