What is the output of this program? [code] #include<stdio.h> #include<stdlib.h> int main() { char *ptr; free(ptr);

What is the output of this program?
Code:
   #include<stdio.h>
   #include<stdlib.h>
   int main()
   {
	   char *ptr;
       free(ptr);
       return 0	   
   }
A. this program will print nothing after execution
B. segmentation fault
C. Aborted (core dumped)
D. none of the mentioned
 
Answer: c
Explanation: This prgram is trying to free the memory which is not available in the heap segment.
Output:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ./san
*** glibc detected *** ./san: free(): invalid pointer: 0x4a77cff4 ***
======= Backtrace: =========
/lib/libc.so.6[0x4a6489f2]
./san[0x80483c9]
/lib/libc.so.6(__libc_start_main+0xf3)[0x4a5e96b3]
./san[0x8048321]
======= Memory map: ========
08048000-08049000 r-xp 00000000 fd:01 394194 /home/123hoidap/san
08049000-0804a000 rw-p 00000000 fd:01 394194 /home/123hoidap/san
09233000-09254000 rw-p 00000000 00:00 0 [heap]
4a5ab000-4a5cc000 r-xp 00000000 fd:01 785334 /lib/ld-2.14.90.so
4a5cc000-4a5cd000 r–p 00020000 fd:01 785334 /lib/ld-2.14.90.so
4a5cd000-4a5ce000 rw-p 00021000 fd:01 785334 /lib/ld-2.14.90.so
4a5d0000-4a77a000 r-xp 00000000 fd:01 789110 /lib/libc-2.14.90.so
4a77a000-4a77b000 —p 001aa000 fd:01 789110 /lib/libc-2.14.90.so
4a77b000-4a77d000 r–p 001aa000 fd:01 789110 /lib/libc-2.14.90.so
4a77d000-4a77e000 rw-p 001ac000 fd:01 789110 /lib/libc-2.14.90.so
4a77e000-4a781000 rw-p 00000000 00:00 0
4a7e0000-4a7fc000 r-xp 00000000 fd:01 789128 /lib/libgcc_s-4.6.2-20111027.so.1
4a7fc000-4a7fd000 rw-p 0001b000 fd:01 789128 /lib/libgcc_s-4.6.2-20111027.so.1
b7724000-b7725000 rw-p 00000000 00:00 0
b773d000-b773f000 rw-p 00000000 00:00 0
b773f000-b7740000 r-xp 00000000 00:00 0 [vdso]
bfc83000-bfca4000 rw-p 00000000 00:00 0 [stack]
Aborted (core dumped)
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top