Merge changes Icb667451,Ie08d910b

* changes:
  Use template instead of macro to release UniquePtrs.
  Make usage of new/delete and malloc/free consistent.