This function attempted to save time by caching the results of a graph cycle
search and then reusing them in a future call. The logic used for this caching
is invalid. It compares graph pointers to see if it is operating on the same
graph as last time, but this can return a false positive if the previous graph
has been deallocated and a new (unrelated) graph has been allocated at the same
address.
This logic would eventually have to be unwound or adjusted in order to support
multithreading in this code too.
It is possible this is the root cause of the issue described in #2162, though I
was never able to reproduce that issue.