How can malloc() cause a SIGSEGV?

前端 未结 6 1537
长情又很酷
长情又很酷 2021-01-02 12:09

I have an odd bug in my program, it appears to me that malloc() is causing a SIGSEGV, which as far as my understanding goes does not make any sense. I am using a library cal

6条回答
  •  耶瑟儿~
    2021-01-02 12:26

    Probably memory violation occurs in other part of your code. If you are on Linux, you should definitely try valgrind. I would never trust my own C programs unless it passes valgrind.

    EDIT: another useful tool is Electric fence. Glibc also provides the MALLOC_CHECK_ environmental variable to help debug memory problems. These two methods do not affect running speed as much as valgrind.

提交回复
热议问题