hack to avoid segv on memory free. needs to be fixed properly