I think the best way is borrowing constructor and destructor concepts from C++. For each internal data structure <em><strong>foo</strong></em>, maintain a <em><strong>foo_create</strong></em> function as the constructor(many data structures are already done), and a <em><strong>foo_destroy</strong></em> function as the destructor. Then we avoid duplicate and complicate clean work at each failure exit in <strong><em>foo_create</em></strong>.<br>

<br>
<div class="gmail_quote">2010/11/23 Kristian Høgsberg <span dir="ltr">&lt;<a href="mailto:krh@bitplanet.net">krh@bitplanet.net</a>&gt;</span><br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="im">On Wed, Nov 17, 2010 at 10:16 PM, 林昊翔 &lt;<a href="mailto:linhaoxiang@gmail.com">linhaoxiang@gmail.com</a>&gt; wrote:<br>&gt; The scenario is:<br>&gt; struct A *foo()<br>&gt; {<br>&gt;     A *a;<br>&gt;<br>

&gt;     a = malloc(sizeof(A));<br>&gt;     if (a == NULL)<br>&gt;         return NULL;<br>&gt;<br>&gt;     a-&gt;b = malloc(sizeof(B));<br>&gt;     if (a-&gt;b == NULL)<br>&gt;         return NULL;<br>&gt;<br>&gt;     return a;<br>

&gt; }<br><br></div>You&#39;re right, there&#39;s a bunch of those in the code.  Could you please<br>create your patches by committing the changes and then either attach<br>the output of git format-patch -1 (where -1 means &quot;one commit&quot;, use<br>

whatever number of patches you have) or even better use git send-email<br>-1 --to=<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a>.<br><br>Thanks,<br><font color="#888888">Kristian<br>

</font></blockquote></div><br>