Hi nobled,<br><br><div class="gmail_quote">On Fri, Dec 3, 2010 at 12:08 AM, nobled <span dir="ltr"><<a href="mailto:nobled@dreamwidth.org">nobled@dreamwidth.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Minimize code duplication and avoid null-free in case any of<br>
the allocations failed.<br>
---<br>
src/gallium/drivers/r300/r300_context.c | 30 +++++++++---------------------<br>
1 files changed, 9 insertions(+), 21 deletions(-)<br>
<br>
diff --git a/src/gallium/drivers/r300/r300_context.c<br>
b/src/gallium/drivers/r300/r300_context.c<br>
index 2b06a24..757da60 100644<br>
--- a/src/gallium/drivers/r300/r300_context.c<br>
+++ b/src/gallium/drivers/r300/r300_context.c<br>
@@ -139,27 +139,11 @@<br>
<br>
r300_update_num_contexts(r300->screen, -1);<br>
<br>
- /* Free the structs allocated in r300_setup_atoms() */<br>
- if (r300->aa_state.state) {<br>
- FREE(r300->aa_state.state);<br>
- FREE(r300->blend_color_state.state);<br>
- FREE(r300->clip_state.state);<br>
- FREE(r300->fb_state.state);<br>
- FREE(r300->gpu_flush.state);<br>
- FREE(r300->hyperz_state.state);<br>
- FREE(r300->invariant_state.state);<br>
- FREE(r300->rs_block_state.state);<br>
- FREE(r300->scissor_state.state);<br>
- FREE(r300->textures_state.state);<br>
- FREE(r300->vap_invariant_state.state);<br>
- FREE(r300->viewport_state.state);<br>
- FREE(r300->ztop_state.state);<br>
- FREE(r300->fs_constants.state);<br>
- FREE(r300->vs_constants.state);<br>
- if (!r300->screen->caps.has_tcl) {<br>
- FREE(r300->vertex_stream_state.state);<br>
- }<br>
- }<br>
+ /* Free the structs allocated in r300_setup_atoms(). */<br>
+ foreach(atom, &r300->atom_list)<br>
+ if (atom->state != NULL)<br>
+ FREE(atom->state);<br>
+<br></blockquote><div><br>I don't think this is correct. We should only release those atoms we allocate manually (as is listed in the code). There are also the atoms in "atom_list" which are set via the pipe_context::bind_* functions and should not be released here. Instead, they should be released by a state tracker using the appropriate delete_* functions. Moreover, free(NULL) is legal and has no effect.<br>
<br>I will commit the other patches. Thanks.<br><br>Best regards<br>Marek<br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
FREE(r300);<br>
}<br>
<br>
@@ -420,11 +404,15 @@<br>
r300->context.destroy = r300_destroy_context;<br>
<br>
make_empty_list(&r300->query_list);<br>
+ make_empty_list(&r300->atom_list);<br>
<br>
util_slab_create(&r300->pool_transfers,<br>
sizeof(struct pipe_transfer), 64,<br>
UTIL_SLAB_SINGLETHREADED);<br>
<br>
+ /* The above calls must not fail, since r300_destroy_context()<br>
+ depends on them. */<br>
+<br>
r300->cs = rws->cs_create(rws);<br>
if (r300->cs == NULL)<br>
goto fail;<br>
<font color="#888888">--<br>
1.7.0.4<br>
</font><br>_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
<br></blockquote></div><br>