Bug 80048 - gcc/sese.c: PVS-Studio: Improper Release of Memory Before Removing Last Reference (CWE-401)
Summary: gcc/sese.c: PVS-Studio: Improper Release of Memory Before Removing Last Refer...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 7.0.1
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-15 14:49 UTC by Phillip Khandeliants
Modified: 2017-03-17 16:29 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-03-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Phillip Khandeliants 2017-03-15 14:49:16 UTC
We have found a weakness (CWE-401) using PVS-Studio tool. PVS-Studio is a static code analyzer for C, C++ and C#: https://www.viva64.com/en/pvs-studio/

Analyzer warning: V625 Consider inspecting the 'for' operator. Initial and final values of the iterator are the same. sese.c 201

void free_sese_info (sese_info_p region)
{
  region->params.release ();
  region->loop_nest.release ();

  for (rename_map_t::iterator it = region->rename_map->begin();
       it != region->rename_map->begin (); ++it)                // <=
    (*it).second.release();
  ....
}
Comment 1 Richard Biener 2017-03-16 14:45:43 UTC
Mine.
Comment 2 Richard Biener 2017-03-17 11:04:05 UTC
Author: rguenth
Date: Fri Mar 17 11:03:32 2017
New Revision: 246217

URL: https://gcc.gnu.org/viewcvs?rev=246217&root=gcc&view=rev
Log:
2017-03-17  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/80048
	* sese.c (free_sese_info): Properly release rename_map and
	copied_bb_map elements.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/sese.c
Comment 3 Richard Biener 2017-03-17 11:04:34 UTC
Fixed.
Comment 4 Martin Sebor 2017-03-17 16:29:45 UTC
I opened bug 80087 to consider enhancing -Wtautological-compare so as to detect and diagnose this class of problems.