Thanks for catching that. I'll add a check for memory_limit == -1.
The current algorithm is only an educated guess. If our guess is wrong, we will run out of memory - same as now. A simple equation (image size * 2) risks raising a lot of false positives. Trying to accurately estimate how much memory GD will use for the destination requires information about the implementation.