分享

程序运行产生SIGABRT信号的原因

 slimfeng 2019-11-21

目前我所知的程序运行产生SIGABRT信号的原因有三个,若还有其他情况,敬请网友留言。

(注:SIGABRT信号即signal 6的信号)

一、多次free导致的SIGABRT

  1. #include "stdlib.h"
  2. #include "string.h"
  3. #include "stdio.h
  4. int main()
  5. {
  6. void *pc = malloc(1024);
  7. free(pc);
  8. //free(pc); //打开注释会导致错误
  9. printf("free ok!\n");
  10. return 0;
  11. }

二、执行abort函数

  1. #include "string.h"
  2. #include "stdio.h"
  3. #include "stdlib.h"
  4. int main()
  5. {
  6. printf("before run abort!\n");
  7. abort();
  8. printf("after run abort!\n");
  9. return 0;
  10. }

三、执行到assert函数
  1. #include "string.h"
  2. #include "stdio.h"
  3. #include "assert.h"
  4. #include "stdlib.h"
  5. int main()
  6. {
  7. printf("before run assert!\n");
  8. #if 0 //该值为0,则报错;为1,则正常
  9. void *pc = malloc(1024);
  10. #else
  11. void *pc = NULL;
  12. #endif
  13. assert( pc != NULL );
  14. printf("after run assert!\n");
  15. return 0;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多