Fix memory leak in bert dict freeing