码迷,mamicode.com
首页 > Web开发 > 详细

A Reusable Aspect for Memory Allocation Checking

时间:2015-06-09 16:42:43      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

The checking logic would be refactored into an aspect file, as follows:

after(void * s) : (call($ malloc(...)) || call($ calloc(...)) || call($ realloc(...))) 
			&& result(s) {
	char * result = (char *)(s);
	if (result == NULL) {
		/* routine to handle the case when memory allocation fails */
	}
} 


Now, the core program looks as follows:

...
int *x ;
x = (int *)malloc(sizeof(int) * 4);		<--- dynamic memory allocation
/* routine for handling the normal case */

...

A Reusable Aspect for Memory Allocation Checking

标签:

原文地址:http://www.cnblogs.com/xiaohuihui123/p/4563753.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!