Fix std::bad_alloc bug in tableindexfactory