Hi All
Please review the program and let me know whether my program will cause memory leak or not.
1 #include <stdio.h>
2
3 struct emp
4 {
5 int empno;
6 char empname[10];
7 } obj;
8
9
10 void copy(struct emp *);
11 void freeStruct(struct emp);
12
13 main()
14 {
15 memset(obj, 0x00, sizeof(obj));
16 copy(&obj);
17 printf("Main Emp No = %d Emp Name = %s\n", obj.empno, obj.empname);
18 }
19
20 void copy(struct emp *e)
21 {
22 struct emp eno;
23
24 memset(eno, 0x00, sizeof(eno));
25 eno.empno = 5;
26 strcpy(eno.empname, "sathish");
27
28 memcpy(e, &eno, sizeof(eno));
29
30 freeStruct(eno);
31
32 printf("Copy Emp No = %d Emp Name = %s\n", eno.empno, eno.empname);
33 }
34
35 void freeStruct(struct emp eno1)
36 {
37 memset(obj, 0x00, sizeof(eno1));
38 }
Output
Segmentation Fault(coredump)
I am getting the expected output due to some problem.
Thanks & Regards
Sathish Kumar