{"id":4803,"date":"2014-03-30T15:31:49","date_gmt":"2014-03-30T15:31:49","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/recursively-freeing-c-structs-collection-of-common-programming-errors\/"},"modified":"2014-03-30T15:31:49","modified_gmt":"2014-03-30T15:31:49","slug":"recursively-freeing-c-structs-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/recursively-freeing-c-structs-collection-of-common-programming-errors\/","title":{"rendered":"Recursively freeing C structs-Collection of common programming errors"},"content":{"rendered":"<p>Take a look at talloc http:\/\/talloc.samba.org\/ if you do:<\/p>\n<pre><code>model* mdl = talloc (NULL, ...);\nmdl-&gt;vertices = talloc (mdl, ...);\nmdl-&gt;normals = talloc (mdl, ...);\nmdl-&gt;uv_coords = talloc (mdl, ...);\nmdl-&gt;quads = talloc (mdl, ...);\nmdl-&gt;triangles = talloc (mdl, ...);\n<\/code><\/pre>\n<p>you can then:<\/p>\n<pre><code>talloc_free(mdl);\n<\/code><\/pre>\n<p>and <code>talloc<\/code> will take care of <code>free<\/code>&#8216;ing all the other blocks you called <code>talloc<\/code> with <code>mdl<\/code> as the first argument at allocation time (and it will do this recursively you can do <code>talloc(mdl-&gt;vertices, ...)<\/code> and <code>talloc_free(mdl);<\/code> will get that too)<\/p>\n<p>as an aside there is a slight overhead to using talloc because it needs to track what stuff recurse over, but it&#8217;s not very much.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Take a look at talloc http:\/\/talloc.samba.org\/ if you do: model* mdl = talloc (NULL, &#8230;); mdl-&gt;vertices = talloc (mdl, &#8230;); mdl-&gt;normals = talloc (mdl, &#8230;); mdl-&gt;uv_coords = talloc (mdl, &#8230;); mdl-&gt;quads = talloc (mdl, &#8230;); mdl-&gt;triangles = talloc (mdl, &#8230;); you can then: talloc_free(mdl); and talloc will take care of free&#8216;ing all the other blocks [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4803","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4803"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4803\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}