[Mesa-dev] [PATCH] glsl: Change loop_analysis to not look like a resource leak

Matt Turner mattst88 at gmail.com
Wed Jan 30 12:00:37 PST 2013


On Wed, Jan 30, 2013 at 11:27 AM, Ian Romanick <idr at freedesktop.org> wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> Previously the loop_state was allocated in the loop_analysis
> constructor, but not freed in the (nonexistent) destructor.  Moving
> the allocation of the loop_state makes this code appear less sketchy.
>
> Either way, there is no actual leak.  The loop_state is freed by the
> single caller of analyze_loop_variables.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> Cc: Dave Airlie <airlied at freedesktop.org>
> Cc: Matt Turner <mattst88 at gmail.com>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=57753
> ---
>  src/glsl/loop_analysis.cpp | 13 ++++++-------
>  src/glsl/loop_analysis.h   |  2 +-
>  2 files changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/src/glsl/loop_analysis.cpp b/src/glsl/loop_analysis.cpp
> index 6a0e4da..191e92d 100644
> --- a/src/glsl/loop_analysis.cpp
> +++ b/src/glsl/loop_analysis.cpp
> @@ -105,7 +105,7 @@ loop_variable_state::insert(ir_if *if_stmt)
>
>  class loop_analysis : public ir_hierarchical_visitor {
>  public:
> -   loop_analysis();
> +   loop_analysis(loop_state *loops);
>
>     virtual ir_visitor_status visit(ir_loop_jump *);
>     virtual ir_visitor_status visit(ir_dereference_variable *);
> @@ -129,12 +129,10 @@ public:
>  };
>
>
> -loop_analysis::loop_analysis()
> +loop_analysis::loop_analysis(loop_state *loops)
> +   : loops(loops), if_statement_depth(0), current_assignment(NULL)
>  {
> -   this->loops = new loop_state;
> -
> -   this->if_statement_depth = 0;
> -   this->current_assignment = NULL;
> +   /* empty */
>  }
>
>
> @@ -521,7 +519,8 @@ is_loop_terminator(ir_if *ir)
>  loop_state *
>  analyze_loop_variables(exec_list *instructions)
>  {
> -   loop_analysis v;
> +   loop_state *loops = new loop_state;
> +   loop_analysis v(loops);
>
>     v.run(instructions);
>     return v.loops;
> diff --git a/src/glsl/loop_analysis.h b/src/glsl/loop_analysis.h
> index 05c982f..769d626 100644
> --- a/src/glsl/loop_analysis.h
> +++ b/src/glsl/loop_analysis.h
> @@ -249,7 +249,7 @@ private:
>
>     void *mem_ctx;
>
> -   friend class loop_analysis;
> +   friend loop_state *analyze_loop_variables(exec_list *instructions);
>  };
>
>  #endif /* LOOP_ANALYSIS_H */
> --
> 1.7.11.7
>

Reviewed-by: Matt Turner <mattst88 at gmail.com>


More information about the mesa-dev mailing list