I was running down a crash today and traced it to the moral equivalent of:
pub fn global_deinit(ga: *GA) void {
ga.mx.lock();
defer ga.mx.unlock();
// ... lots of intervening code setting things to invalid so use-after-free gets caught
// Finally, we can clear the lock
ga.mx = undefined; // Whoops. This blasts the lock before defer can run
}
Is there anything that I could have done to have caught this at compile?
Solution is:
pub fn global_deinit(ga: *GA) void {
ga.mx.lock();
defer {
ga.mx.unlock();
ga.mx = undefined;
}
// ... code
}