I am debugging a crash where we have a code snippet similar to -
1184 static void
1185 xyz_delete (<struct type1> *c, <struct type2> **a)
1186 {
...
...
...
...
1196 b = *a;
1197 if (!b) {
1198 return;
1199 }
...
...
1203 prev = b->next;
1204 b->next = NULL;
...
...
1245 free_timer(b->active_timer);
...
...
...
}
And we happened to see a crash - segmentation fault; whose callstack is shown below -
#1 0x456789123 in __free [__be___free] (ptr=<optimized out>, saved_caller_pc=0x123456789 , attr=0x0) at free.c:1234
#2 0x345678912 in xyz_delete [__be_xyz_delete...] (c=c@entry=0x234567891, a=a@entry=0x0) at myfile.c:1245
#3 0x455678912 in abc (apple=0x52453545, a=<optimized out>, hello=12) at myfile:1312
From the call stack, we can notice the 2nd argument a passed to function xyz_delete is NULL. However, when we dereferenced a at line# 1196, there is no crash - which is really surprising! And there are few read and write operations being performed on b at line# 1203 and 1204. But a segmentation fault is seen when free_timer is called on b->active_timer at line# 1245. free_timer inturn calls free.
How could a NULL pointer be dereferenced without causing a crash?
Any logical explanation for what could be happening here?