Revert "Revert "fix freeing memory ( strdup should require free() )""

This reverts commit 4f8538a70ae8cd5e61c8c27e7c7476cd01248b86.