When a pointer is allocated memory using malloc, pointer (say x)will now point to memory address. Later I free this(x) memory pointer,but pointer is still pointing to it's old memory. This would now create dangling pointer. (Because I did not point the old pointer to NULL after free)
Now, assume I use malloc and assume new pointer(y) now points to same memory location as old pointer (x) Doesn't memsetting new pointer (y) to 0 solve dangling pointer issue.
Assume I have only one struct type.So every malloc which I do is always of same size of same structure. If it was different struct , I know i may still have some data at the end of struct if new pointer (y) has small memory allocation than pointer (x)