title: std::unique_ptr for C functions that need free
body: <p>Think to a C function that return something that must be <code>free</code>d, for example the POSIX's <code>strdup()</code>. I want to use that function in C++11 and avoid any chance of leaks, is this a correct way?</p>
  
  <pre><code>#include &lt;memory&gt;
  #include &lt;iostream&gt;
  #include &lt;string.h&gt;
  
  int main() {
      char const* t { "Hi stackoverflow!" };
      std::unique_ptr&lt;char, void(*)(void*)&gt;
          t_copy { strdup(t), std::free };
  
      std::cout &lt;&lt; t_copy.get() &lt;&lt; " &lt;- this is the copy!" &lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>Assuming it makes sense, it is possible to use a similar pattern with non-pointers? For example for the POSIX's function <code>open</code> that returns an <code>int</code>?</p>