- 论坛徽章:
- 59
|
回复 1# 叶叶叶Yeah
don't do that.
in some case, malloc is redefined as specified purpose (ex. locate the bug)- #ifdef malloc
- #undef malloc
- #endif
- struct mheader{
- union{
- char tag[1];
- long long ll[8];
- }tag;
- void *p;
- };
- void *_inner_malloc(size_t _Size,char *context){
- void *_innerp=NULL;
- struct mheader* pm=(struct mheader *)malloc(sizeof(struct mheader)+_Size);
- if(pm){
- strncpy(pm->tag.tag,context,sizeof(pm->tag.ll));
- _innerp=&pm->p;
- }
- return _innerp;
- }
- #ifdef free
- #undef free
- #endif
- void _inner_free(void *p){
- if(p!=NULL){
- struct mheader* pm=(struct mheader*)(((char *)p)-(int)&((struct mheader *)0)->p);
- free(p);
- }
- }
- #define malloc(x) _inner_malloc(x,__FILE__)
- #define free _inner_free
复制代码 |
|