Fix use after free: var->toString(i).c_str()
Pointer returned by c_str() is only valid until temporary object, returned by var->toString(i) is not destroyed.
Coverity CID 1034470, 1034472