TS-2344: fixed problem with freeing the string