This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: malloc/free question..
- From: niXman <i dot nixman at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 17 Mar 2012 03:22:33 +0400
- Subject: Re: malloc/free question..
- References: <4f63ca6a.434fb60a.3a21.5cf3SMTPIN_ADDED@mx.google.com>
2012/3/17 I Rattan <ratta1i@cps.cmich.edu>:
>
> Under Linux with gcc version 4.4.6 (Debian 4.4.6-11)
>
> The following code:
>
> int main(int argv, char** args)
> {
> Âint *arr;
> Âint n;
>
> Ân = 10000000;
>
> Âarr = (int *)malloc(4*n);
> Âfree((void *)&arr);
> Âexit(0);
> }
>
> generates warning:
>
> Â Â Â Âerr.c:14: warning: attempt to free a non-heap object 'arr'
>
> any ideas?
>
> -ishwar
>
int main(int argv, char** args)
{
int *arr;
int n;
n = 10000000;
arr = (int *)malloc(4*n);
//free((void *)&arr);
free(arr);
exit(0);
}
http://liveworkspace.org/code/a6a92573a92d663fd7f863225863f0f7
--
Regards,
 niXman