Message ID | 1416577889-18404-1-git-send-email-zodiac@ispras.ru |
---|---|
State | New |
Headers | show |
Nikita Belov <zodiac@ispras.ru> writes: > Variable 'ram_lo' is allocated unconditionally, but used only in some cases. > When it is unused pointer will be lost at function exit, resulting in a > memory leak. Allocate memory for 'ram_lo' only if it is needed. > > Valgrind output: > ==16879== 240 bytes in 1 blocks are definitely lost in loss record 6,033 of 7,018 > ==16879== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) > ==16879== by 0x33D2CE: malloc_and_trace (vl.c:2804) > ==16879== by 0x509E610: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4000.0) > ==16879== by 0x288836: realview_init (realview.c:55) > ==16879== by 0x28988C: realview_pb_a8_init (realview.c:375) > ==16879== by 0x341426: main (vl.c:4413) > > Signed-off-by: Nikita Belov <zodiac@ispras.ru> Reviewed-by: Markus Armbruster <armbru@redhat.com>
On 21 November 2014 at 13:51, Nikita Belov <zodiac@ispras.ru> wrote: > Variable 'ram_lo' is allocated unconditionally, but used only in some cases. > When it is unused pointer will be lost at function exit, resulting in a > memory leak. Allocate memory for 'ram_lo' only if it is needed. > > Valgrind output: > ==16879== 240 bytes in 1 blocks are definitely lost in loss record 6,033 of 7,018 > ==16879== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) > ==16879== by 0x33D2CE: malloc_and_trace (vl.c:2804) > ==16879== by 0x509E610: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4000.0) > ==16879== by 0x288836: realview_init (realview.c:55) > ==16879== by 0x28988C: realview_pb_a8_init (realview.c:375) > ==16879== by 0x341426: main (vl.c:4413) > > Signed-off-by: Nikita Belov <zodiac@ispras.ru> > --- Applied to target-arm.next; thanks. -- PMM
diff --git a/hw/arm/realview.c b/hw/arm/realview.c index af65aa4..9bf2392 100644 --- a/hw/arm/realview.c +++ b/hw/arm/realview.c @@ -52,7 +52,7 @@ static void realview_init(MachineState *machine, CPUARMState *env; ObjectClass *cpu_oc; MemoryRegion *sysmem = get_system_memory(); - MemoryRegion *ram_lo = g_new(MemoryRegion, 1); + MemoryRegion *ram_lo; MemoryRegion *ram_hi = g_new(MemoryRegion, 1); MemoryRegion *ram_alias = g_new(MemoryRegion, 1); MemoryRegion *ram_hack = g_new(MemoryRegion, 1); @@ -135,6 +135,7 @@ static void realview_init(MachineState *machine, if (is_pb && ram_size > 0x20000000) { /* Core tile RAM. */ + ram_lo = g_new(MemoryRegion, 1); low_ram_size = ram_size - 0x20000000; ram_size = 0x20000000; memory_region_init_ram(ram_lo, NULL, "realview.lowmem", low_ram_size,
Variable 'ram_lo' is allocated unconditionally, but used only in some cases. When it is unused pointer will be lost at function exit, resulting in a memory leak. Allocate memory for 'ram_lo' only if it is needed. Valgrind output: ==16879== 240 bytes in 1 blocks are definitely lost in loss record 6,033 of 7,018 ==16879== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==16879== by 0x33D2CE: malloc_and_trace (vl.c:2804) ==16879== by 0x509E610: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4000.0) ==16879== by 0x288836: realview_init (realview.c:55) ==16879== by 0x28988C: realview_pb_a8_init (realview.c:375) ==16879== by 0x341426: main (vl.c:4413) Signed-off-by: Nikita Belov <zodiac@ispras.ru> --- hw/arm/realview.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)