[gparted] Stop leaking PedGeometry object memory (#767009)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Stop leaking PedGeometry object memory (#767009)
- Date: Mon, 30 May 2016 17:13:09 +0000 (UTC)
commit 3724421e3037d1faeeefe1786c8908431b313334
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Wed Apr 20 13:25:30 2016 +0100
Stop leaking PedGeometry object memory (#767009)
Calling libparted ped_geometry_new() creates a new PedGeometry object
from malloced memory, however the corresponding ped_geometry_destroy()
is never called to destroy the object and free the memory.
Perform a resize of a FAT file system when running GParted under
valgrind identifies several memory blocks leaked via ped_geometry_new()
from resize_move_filesystem_using_libparted(). One such example:
# valgrind --track-origins=yes --leak-check=full ./gpartedbin
...
==32069== 32 bytes in 1 blocks are definitely lost in loss record 5,419 of 11,542
==32069== at 0x4C29BFD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==32069== by 0x8ECD8C5: ped_malloc (libparted.c:231)
==32069== by 0x8ED23C1: ped_geometry_new (geom.c:79)
==32069== by 0x4764F3:
GParted::GParted_Core::resize_move_filesystem_using_libparted(GParted::Partition const&, GParted::Partition
const&, GParted::OperationDetail&) (GParted_Core.cc:2666)
==32069== by 0x478007: GParted::GParted_Core::resize_filesystem(GParted::Partition const&,
GParted::Partition const&, GParted::OperationDetail&, bool) (GParted_Core.cc:2990)
==32069== by 0x478440: GParted::GParted_Core::maximize_filesystem(GParted::Partition const&,
GParted::OperationDetail&) (GParted_Core.cc:3037)
==32069== by 0x4769A0: GParted::GParted_Core::resize(GParted::Partition const&, GParted::Partition
const&, GParted::OperationDetail&) (GParted_Core.cc:2746)
==32069== by 0x47582B: GParted::GParted_Core::resize_move(GParted::Partition const&,
GParted::Partition&, GParted::OperationDetail&) (GParted_Core.cc:2457)
==32069== by 0x46DDB2: GParted::GParted_Core::apply_operation_to_disk(GParted::Operation*)
(GParted_Core.cc:767)
...
There is also a leak of a PedGeometry object from
resize_move_partition(). Fix by calling ped_geometry_destroy() to
delete all the allocated PedGeometry objects and free the memory.
Bug 767009 - PedGeometry objects are memory leaked
src/GParted_Core.cc | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index bc5a355..9768ab8 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -2179,7 +2179,10 @@ bool GParted_Core::create_partition( Partition & new_partition, OperationDetail
new_partition .get_sector_length() ) ;
if ( geom )
+ {
constraint = ped_constraint_exact( geom ) ;
+ ped_geometry_destroy( geom );
+ }
}
else
constraint = ped_constraint_any( lp_device );
@@ -2673,9 +2676,12 @@ bool GParted_Core::resize_move_filesystem_using_libparted( const Partition & par
if ( lp_geom )
{
fs = ped_file_system_open( lp_geom );
+
+ ped_geometry_destroy( lp_geom );
+ lp_geom = NULL;
+
if ( fs )
{
- lp_geom = NULL ;
lp_geom = ped_geometry_new( lp_device,
partition_new .sector_start,
partition_new .get_sector_length() ) ;
@@ -2692,6 +2698,8 @@ bool GParted_Core::resize_move_filesystem_using_libparted( const Partition & par
if ( return_value )
commit( lp_disk ) ;
+
+ ped_geometry_destroy( lp_geom );
}
ped_file_system_close( fs );
@@ -2875,7 +2883,11 @@ bool GParted_Core::resize_move_partition( const Partition & partition_old,
PedGeometry *geom = ped_geometry_new( lp_device,
partition_new .sector_start,
partition_new .get_sector_length()
) ;
- constraint = ped_constraint_exact( geom ) ;
+ if ( geom )
+ {
+ constraint = ped_constraint_exact( geom );
+ ped_geometry_destroy( geom );
+ }
}
else
constraint = ped_constraint_any( lp_device ) ;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]