getCtxFromFile(): fixed resource leaks in errorcase