I have a base class static character pointer d, which is called by 3 members in derived class in the following fashion
BaseClass::d = strdup(x);
//x is a character pointer whose value changes during execution.
Each time when this code is executed, character pointer d is overwritten and it cause memory leak. To prevent this memory leak, I want to call free(d) before strdup.
What will happen if free(d) is called when no memory is allocated to d(Initial case)?
How I can check if d is null pointer or not before calling free? Or is it safe to call free without this check?