The Horror in the Standard Library
OMG, as I was reading this I thought, &quot;man, this reminds me of a bug I ran into with std::string back in 2000&quot;, A few sentences later, and this is also about std::string and the STL.<p>Mine was different though, after tracking down a memory leak that was happening with the creation of just new empty string, I discovered in the stdlib that there was a shared pointer to the empty string with a reference count of how many locations were using it (ironic that this was intended to save allocations). It turned out this was on Intel and we had what was rare at the time, a multi-processor system. It turned out that the std::string empty string reference count was just doing a vanilla ++, no locking, nothing, variable not marked volatile, nothing.<p>A few emails with a guy in Australia, a little inline assembly to call a new atomic increment on the counter, and the bug was fixed. That took two weeks to track down, mostly because it didn&#x27;t even cross my mind that it wasn&#x27;t in my code.<p>From that point on, I realized you can&#x27;t trust libraries blindly, even one of the most used and broadly adopted ones out there.