Apparent fix for "Attempt to free unreferenced scalar"