public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: "Martin Liška" <mliska@suse.cz>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH 8/N] Fix memory leak in tree-vectorizer.h
Date: Tue, 08 Dec 2015 12:01:00 -0000	[thread overview]
Message-ID: <CAFiYyc1CQD30FjhMYDctaaWeppq3EMaEfPYwmYXdguE5AZd-fA@mail.gmail.com> (raw)
In-Reply-To: <5666BF73.9040907@suse.cz>

On Tue, Dec 8, 2015 at 12:30 PM, Martin Liška <mliska@suse.cz> wrote:
> Hello.
>
> The patch removes memory leaks that are caused by overwriting an existing
> item in stmt_vec_info_vec (in set_vinfo_for_stmt). My first attempt was to call
> free_stmt_vec_info for old entries that are overwritten, but it caused double frees
> as there are some references between stmt_vec_infos.
>
> So that I've decided to allocate all stmt_vec_info structures from a memory pool, which
> is released in free_stmt_vec_info_vec routine. Replacing 'vec' (used for simd_clone_info and same_align_regs) to 'auto_vec'
> helps to reduce another leaks. To be honest, the solution is not ideal as destructor
> of there auto_vec is not called, however with the patch applied, there is just a single memory leak
> in the whole test-suite related to tree-vect-stmts.c (which is unrelated to these vectors).
>
> Patch can bootstrap and survives regression tests on x86_64-unknown-linux-gnu.
>
> Ready for trunk?

 new_stmt_vec_info (gimple *stmt, vec_info *vinfo)
 {
   stmt_vec_info res;
-  res = (stmt_vec_info) xcalloc (1, sizeof (struct _stmt_vec_info));
+  res = stmt_vec_info_pool.allocate ();

previously it was zeroed memory now it is no longer (AFAIK).

ICK.  You do

+struct _stmt_vec_info
+{
+  _stmt_vec_info (): type ((enum stmt_vec_info_type) 0), live (false),
+  in_pattern_p (false), stmt (NULL), vinfo (0), vectype (NULL_TREE),
+  vectorized_stmt (NULL), data_ref_info (0), dr_base_address (NULL_TREE),
+  dr_init (NULL_TREE), dr_offset (NULL_TREE), dr_step (NULL_TREE),
+  dr_aligned_to (NULL_TREE), loop_phi_evolution_base_unchanged (NULL_TREE),
+  loop_phi_evolution_part (NULL_TREE), related_stmt (NULL),
pattern_def_seq (0),
+  same_align_refs (0), simd_clone_info (0), def_type ((enum vect_def_type) 0),
+  slp_type ((enum slp_vect_type) 0), first_element (NULL), next_element (NULL),
+  same_dr_stmt (NULL), size (0), store_count (0), gap (0), min_neg_dist (0),
+  relevant ((enum vect_relevant) 0), vectorizable (false),
+  gather_scatter_p (false), strided_p (false), simd_lane_access_p (false),
+  v_reduc_type ((enum vect_reduction_type) 0) {}

where I think a

  _stmt_vec_info () { memset (this, 0, sizeof (_stmt_vec_info)); }

would be much nicer.  Or just keep the struct as a POD and add that memset
at the allocation point.  (and double-check the C++ alloc-pool doesn't end up
zeroing everything twice that way...)

Note that overwriting an existing entry in stmt_vec_info_vec should not happen.
In which path does that it happen?  We probably should assert the entry
is NULL.

Thus your fix shouldn't be necessary.

Thanks,
Richard.


> Martin

  reply	other threads:[~2015-12-08 12:01 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
2015-11-23 13:52 ` [PATCH 2/6] Fix memory leak in tree-ssa marxin
2015-11-26 21:01   ` Martin Liška
2015-11-23 13:52 ` [PATCH 5/6] Fix parser memory leak in cilk_simd_fn_info marxin
2015-11-23 20:13   ` Jeff Law
2015-11-23 13:52 ` [PATCH 3/6] Fix memory leaks in IPA devirt marxin
2015-11-23 22:38   ` Trevor Saunders
2015-11-26 21:04     ` Martin Liška
2015-11-23 13:52 ` [PATCH 6/6] Fix memory leak in tree-chkp.c marxin
2015-11-23 13:52 ` [PATCH 4/6] Fix memory leak in loop_vec_info marxin
2015-11-23 13:53 ` [PATCH 1/6] Fix memory leak in cilk marxin
2015-11-23 20:29   ` Trevor Saunders
2015-11-26 21:00   ` Martin Liška
2015-11-27  9:23     ` Bernd Schmidt
2015-11-27  9:40       ` Martin Liška
2015-11-23 14:38 ` [PATCH 0/6] Another fixes of various memory leaks Bernd Schmidt
2015-11-23 15:12   ` Martin Liška
2015-11-26 23:21 ` [PATCH 7/N] Fix newly introduced memory leak in tree-ssa-loop-ivopts.c Martin Liška
2015-11-27  7:03   ` Bin.Cheng
2015-11-27  8:31     ` Martin Liška
2015-11-27  8:45       ` Bin.Cheng
2015-12-08 11:31 ` [PATCH 8/N] Fix memory leak in tree-vectorizer.h Martin Liška
2015-12-08 12:01   ` Richard Biener [this message]
2015-12-08 12:38     ` Richard Biener
2015-12-08 11:32 ` [PATCH 9/N] Fix memory leak tree-if-conv.c Martin Liška
2015-12-08 11:48   ` Bernd Schmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFiYyc1CQD30FjhMYDctaaWeppq3EMaEfPYwmYXdguE5AZd-fA@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mliska@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).