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"><<a href="mailto:krh@bitplanet.net">krh@bitplanet.net</a>></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, 林昊翔 <<a href="mailto:linhaoxiang@gmail.com">linhaoxiang@gmail.com</a>> wrote:<br>> The scenario is:<br>> struct A *foo()<br>> {<br>> A *a;<br>><br>
> a = malloc(sizeof(A));<br>> if (a == NULL)<br>> return NULL;<br>><br>> a->b = malloc(sizeof(B));<br>> if (a->b == NULL)<br>> return NULL;<br>><br>> return a;<br>
> }<br><br></div>You're right, there'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 "one commit", 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>