Author: ycwu
Date: 2011-07-26 05:19:24 -0400 (Tue, 26 Jul 2011)
New Revision: 3702
Modified:
trunk/osprey/be/cg/cgdwarf.cxx
trunk/osprey/libdwarf/dwf_section.c
trunk/osprey/libdwarf/libdwarf/pro_section.c
Log:
fix several memory leaks.
CR by Sun Chan
Modified: trunk/osprey/be/cg/cgdwarf.cxx
===================================================================
--- trunk/osprey/be/cg/cgdwarf.cxx 2011-07-26 08:20:18 UTC (rev 3701)
+++ trunk/osprey/be/cg/cgdwarf.cxx 2011-07-26 09:19:24 UTC (rev 3702)
@@ -101,6 +101,7 @@
#include "data_layout.h"
#include "dwarf_DST.h"
#include "dwarf_DST_mem.h"
+#include "ir_reader.h"
#include "const.h"
#include "cg.h"
#include "cgtarget.h"
@@ -136,6 +137,17 @@
#define GLOBAL_LEVEL 0
#define LOCAL_LEVEL 1
+// the class Scope_Dwarf_Expr_Ptr is used for deallocate the allocated
+// Dwarf_P_Expr pointer in C++ way
+class Scope_Dwarf_Expr_Ptr
+{
+ public:
+ Scope_Dwarf_Expr_Ptr(Dwarf_P_Expr p) : _ptr(p) {}
+ ~Scope_Dwarf_Expr_Ptr() { dwarf_p_dealloc(_ptr, DW_DLA_STRING); }
+ private:
+ Dwarf_P_Expr _ptr;
+};
+
struct CGD_SYMTAB_ENTRY {
CGD_SYMTAB_ENTRY_TYPE type;
Dwarf_Unsigned index;
@@ -681,7 +693,6 @@
DST_SUBPROGRAM *attr,
Dwarf_P_Die die)
{
- Dwarf_P_Expr expr;
if (DST_IS_memdef(flag)) /* Not yet supported */ {
ErrMsg (EC_Unimplemented,
@@ -710,7 +721,8 @@
dwarf_add_AT_unsigned_const(dw_dbg, die, DW_AT_virtuality,
DST_SUBPROGRAM_decl_virtuality(attr),
&dw_error);
- expr = dwarf_new_expr(dw_dbg, &dw_error);
+ Dwarf_P_Expr expr = dwarf_new_expr(dw_dbg, &dw_error);
+ Scope_Dwarf_Expr_Ptr expr_ptr(expr);
dwarf_add_expr_gen(expr,
DW_OP_const2u,
DST_SUBPROGRAM_decl_vtable_elem_location(attr),
@@ -797,7 +809,8 @@
dwarf_add_AT_unsigned_const(dw_dbg, die, DW_AT_virtuality,
DST_SUBPROGRAM_def_virtuality(attr),
&dw_error);
- expr = dwarf_new_expr(dw_dbg, &dw_error);
+ Dwarf_P_Expr expr = dwarf_new_expr(dw_dbg, &dw_error);
+ Scope_Dwarf_Expr_Ptr expr_ptr(expr);
dwarf_add_expr_gen(expr,
DW_OP_const2u,
DST_SUBPROGRAM_def_vtable_elem_location(attr),
@@ -913,7 +926,6 @@
Dwarf_P_Die die,
Dwarf_Half loc_attr)
{
- Dwarf_P_Expr expr;
ST *st;
ST *base_st;
INT64 base_ofst;
@@ -950,7 +962,8 @@
if (DST_IS_deref(flag)) /* f90 formals, dope, etc */
deref = TRUE;
- expr = dwarf_new_expr (dw_dbg, &dw_error);
+ Dwarf_P_Expr expr = dwarf_new_expr (dw_dbg, &dw_error);
+ Scope_Dwarf_Expr_Ptr expr_ptr(expr);
if (st == base_st && ST_class(st) != CLASS_BLOCK
&& ST_sclass(st) != SCLASS_COMMON && ST_sclass(st) != SCLASS_EXTERN)
@@ -1565,8 +1578,6 @@
static void
put_member(DST_flag flag, DST_MEMBER *attr, Dwarf_P_Die die)
{
- Dwarf_P_Expr expr;
-
put_decl(DST_MEMBER_decl(attr), die);
put_name (DST_MEMBER_name(attr), die, pb_none);
put_reference (DST_MEMBER_type(attr), DW_AT_type, die);
@@ -1587,7 +1598,8 @@
* decl and static flags are set at same time,
* so use decl flag. */
/* For now, assume that the member location is always a constant. */
- expr = dwarf_new_expr (dw_dbg, &dw_error);
+ Dwarf_P_Expr expr = dwarf_new_expr (dw_dbg, &dw_error);
+ Scope_Dwarf_Expr_Ptr expr_ptr(expr);
#ifdef KEY
// the dwarf spec says that the location expression for a structure
member
// assumes that the location of the struct itself is on the stack.
This
@@ -1647,10 +1659,11 @@
static void
put_inheritance(DST_flag flag, DST_INHERITANCE *attr, Dwarf_P_Die die)
{
+ put_reference (DST_INHERITANCE_type(attr), DW_AT_type, die);
+
Dwarf_P_Expr expr;
-
- put_reference (DST_INHERITANCE_type(attr), DW_AT_type, die);
expr = dwarf_new_expr (dw_dbg, &dw_error);
+ Scope_Dwarf_Expr_Ptr expr_ptr( expr);
#ifdef KEY
// Bug 3107
// Quote from Dave's last fix:
@@ -2335,7 +2348,6 @@
{
DST_INFO *info;
Dwarf_P_Die PU_die;
- Dwarf_P_Expr expr;
Dwarf_P_Fde fde;
#ifdef TARG_X8664
Dwarf_P_Fde eh_fde = 0;
@@ -2396,7 +2408,8 @@
}
/* setup the frame_base attribute. */
- expr = dwarf_new_expr (dw_dbg, &dw_error);
+ Dwarf_P_Expr expr = dwarf_new_expr (dw_dbg, &dw_error);
+ Scope_Dwarf_Expr_Ptr expr_ptr(expr);
#ifndef TARG_X8664
#ifndef TARG_NVISA /* no stack frames yet */
if (Current_PU_Stack_Model != SMODEL_SMALL)
@@ -2733,7 +2746,6 @@
#endif
}
-
}
#ifdef KEY
Modified: trunk/osprey/libdwarf/dwf_section.c
===================================================================
--- trunk/osprey/libdwarf/dwf_section.c 2011-07-26 08:20:18 UTC (rev 3701)
+++ trunk/osprey/libdwarf/dwf_section.c 2011-07-26 09:19:24 UTC (rev 3702)
@@ -636,6 +636,7 @@
curfde = curfde->fde_next;
}
+ _dwarf_p_dealloc(dbg, cie_offs);
return (int)dbg->de_n_debug_sect;
}
Modified: trunk/osprey/libdwarf/libdwarf/pro_section.c
===================================================================
--- trunk/osprey/libdwarf/libdwarf/pro_section.c 2011-07-26 08:20:18 UTC
(rev 3701)
+++ trunk/osprey/libdwarf/libdwarf/pro_section.c 2011-07-26 09:19:24 UTC
(rev 3702)
@@ -904,6 +904,7 @@
}
curline = curline->dpl_next;
}
+ _dwarf_p_dealloc(dbg, prevline);
/* write total length field */
du = sum_bytes - uwordb_size - extension_size; /* subtract
@@ -1400,6 +1401,7 @@
curfde = curfde->fde_next;
}
+ _dwarf_p_dealloc(dbg, cie_offs);
return (int) dbg->de_n_debug_sect;
}
------------------------------------------------------------------------------
Magic Quadrant for Content-Aware Data Loss Prevention
Research study explores the data loss prevention market. Includes in-depth
analysis on the changes within the DLP market, and the criteria used to
evaluate the strengths and weaknesses of these DLP solutions.
http://www.accelacomm.com/jaw/sfnl/114/51385063/
_______________________________________________
Open64-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/open64-devel