Skip to content

Commit 2c8c283

Browse files
ivanivanov884jeffmahoney
authored andcommitted
gdb-rhbz1007614-memleak-infpy_read_memory-test.patch
;; Fix 'memory leak in infpy_read_memory()' (RH BZ 1007614) ;;=fedoratest Original message by Tom Tromey: <https://sourceware.org/ml/gdb-patches/2012-03/msg00955.html> Message-ID: <[email protected]> Comment from Sergio Durigan Junior: In order to correctly test this patch, I wrote a testcase based on Jan Kratochvil's <gdb/testsuite/gdb.base/gcore-excessive-memory.exp>. The testcase, which can be seen below, tests GDB in order to see if the amount of memory being leaked is minimal, as requested in the bugzilla. It is hard to define what "minimum" is, so I ran the testcase on all supported RHEL architectures and came up with an average. commit cc0265c Author: Tom Tromey <[email protected]> Date: Wed Mar 28 17:38:08 2012 +0000 * python/py-inferior.c (infpy_read_memory): Remove cleanups and explicitly free 'buffer' on exit paths. Decref 'membuf_object' before returning.
1 parent 0995536 commit 2c8c283

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* This testcase is part of GDB, the GNU debugger.
2+
3+
Copyright 2014 Free Software Foundation, Inc.
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>. */
17+
18+
static struct x
19+
{
20+
char unsigned u[4096];
21+
} x, *px = &x;
22+
23+
int
24+
main (int argc, char *argv[])
25+
{
26+
return 0;
27+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright 2014 Free Software Foundation, Inc.
2+
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
set testfile py-gdb-rhbz1007614-memleak-infpy_read_memory
17+
set srcfile ${testfile}.c
18+
set binfile [standard_output_file ${testfile}]
19+
20+
if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
21+
return -1
22+
}
23+
24+
if { [skip_python_tests] } { continue }
25+
26+
set pid_of_gdb [exp_pid -i [board_info host fileid]]
27+
28+
proc memory_v_pages_get {} {
29+
global pid_of_gdb
30+
set fd [open "/proc/$pid_of_gdb/statm"]
31+
gets $fd line
32+
close $fd
33+
# number of pages of virtual memory
34+
scan $line "%d" drs
35+
return $drs
36+
}
37+
38+
if { ![runto_main] } {
39+
untested $testfile.exp
40+
return -1
41+
}
42+
43+
set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py]
44+
45+
gdb_test "source ${remote_python_file}" ""
46+
47+
gdb_test "hello-world" ""
48+
49+
set kbytes_before [memory_v_pages_get]
50+
verbose -log "kbytes_before = $kbytes_before"
51+
52+
gdb_test "hello-world" ""
53+
54+
set kbytes_after [memory_v_pages_get]
55+
verbose -log "kbytes_after = $kbytes_after"
56+
57+
set kbytes_diff [expr $kbytes_after - $kbytes_before]
58+
verbose -log "kbytes_diff = $kbytes_diff"
59+
60+
# The value "1000" was calculated by running a few GDB sessions with this
61+
# testcase, and seeing how much (in average) the memory consumption
62+
# increased after the "hello-world" command issued above. The average
63+
# was around 500 bytes, so I chose 1000 as a high estimate.
64+
if { $kbytes_diff > 1000 } {
65+
fail "there is a memory leak on GDB (RHBZ 1007614)"
66+
} else {
67+
pass "there is not a memory leak on GDB (RHBZ 1007614)"
68+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (C) 2014 Free Software Foundation, Inc.
2+
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
16+
class HelloWorld (gdb.Command):
17+
"""Greet the whole world."""
18+
19+
def __init__ (self):
20+
super (HelloWorld, self).__init__ ("hello-world",
21+
gdb.COMMAND_OBSCURE)
22+
23+
def invoke (self, arg, from_tty):
24+
px = gdb.parse_and_eval("px")
25+
core = gdb.inferiors()[0]
26+
for i in range(256 * 1024):
27+
chunk = core.read_memory(px, 4096)
28+
print "Hello, World!"
29+
30+
HelloWorld ()

0 commit comments

Comments
 (0)