Re: accessing freed memory without error

From: bd (bdonlan_at_gmail.com)
Date: 01/17/05


Date: Mon, 17 Jan 2005 15:01:53 -0500


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

sachin_mzn@yahoo.com wrote:

> Hi,
>
> Why I am not getting any run time error while accessing a freed memory
> in following code. This is printing h in std output.
>
> #include<stdio.h>
> main()
> {
> char* buffer = (char*)malloc(6);
> strcpy(buffer,"hello");
> free(buffer);
> printf("buffer=%c\n", *buffer);
> }

The effects of accessing freed memory are undefined. This means anything can
happen, including nothing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFB7Bmx+hz2VlChukwRAuvUAKC0oI2YJBXOxsWO4rAzSqwer8/YtQCfVBfR
lIVTC8MC9YidBIuG9GPcErg=
=TQbd
-----END PGP SIGNATURE-----



Relevant Pages