Other programming questions: segfault in free
Hi all,
I need help in solving a segmentation fault in free. I don't understand why it is giving a segfault even if the address is valid. When I tried to print the pointer passed to free. i is printing a valid address and also the correct content at that address. Then why is it giving a segfault. I have tried it in gdb the result is as follows :-
Here pResp is the pointer i'm tring to free.
[GDB]
817 printf("%s - Resp for operation\n",pResp);
(gdb) n
Added - Resp for operation
819 pResp = pTemp;
(gdb) print pResp
$4 = 0x80506b5 "Added"
(gdb) n
820 free(pResp);
(gdb) print pResp
$5 = 0x8050698 "\001"
(gdb) print pTemp
$6 = 0x8050698 "\001"
(gdb) s
Program received signal SIGSEGV, Segmentation fault.
0x420744fe in _int_free () from /lib/tls/libc.so.6
(gdb) print presp
No symbol "presp" in current context.
(gdb) print pResp
No symbol "pResp" in current context.
(gdb) up
#1 0x420734d6 in free () from /lib/tls/libc.so.6
[/GDB]
Please do tell me where i'm going wrong
Thanks,
Neeharika.