Chinaunix

标题: hp-ux和rh-linux环境下,free函数有什么区别? [打印本页]

作者: together007    时间: 2012-08-31 10:58
标题: hp-ux和rh-linux环境下,free函数有什么区别?
hp-ux和rh-linux环境下,free函数有什么区别吗?
同一套程序,hp-ux环境下调用free正常,linux环境下就会core掉,为什么呢?求高手指点
作者: hellioncu    时间: 2012-08-31 11:08
错肯定在你的代码
作者: folklore    时间: 2012-08-31 11:59
check the following:
1. double free

  1. int *p=(int*)malloc(sizeof(int));
  2. free(p);
复制代码
2. free a local memory

  1. int memblock[1024];
  2. int *pmem=memblock;
  3. free(pmem);  // free may check the parameter, but in some version, it doesn't.
复制代码
3. check free NULL

  1. free(NULL);
复制代码

作者: hellioncu    时间: 2012-08-31 13:49
folklore 发表于 2012-08-31 11:59
check the following:
1. double free2. free a local memory3. check free NULL


没见过有哪个系统free(NULL)会出错的
作者: folklore    时间: 2012-08-31 14:07
回复 4# hellioncu


    you can assume nothing. so , just check it.

作者: hellioncu    时间: 2012-08-31 14:13
folklore 发表于 2012-08-31 14:07
回复 4# hellioncu


free(NULL)什么都不做,这是标准行为




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2