Skip to content

Several memory leaks in TLegend and TLatex #22781

Description

@TomasDado

Check duplicate issues.

  • Checked for duplicates

Description

Hello,

In the recent root versions I see several memory leaks in a simple code that draws TLatex TLegend etc.

See the reproducer below.

Reproducer

leak.cxx

#include "TCanvas.h"
#include "TLatex.h"
#include "TH1D.h"
#include "TLegend.h"

int main(int argc, char **argv){
    TCanvas c("","",400,400);

    TLatex l{};
    l.DrawLatexNDC(0.17, 0.95, "text");

    TH1D h("","", 10, 0, 10);
    TLegend leg(0.7, 0.8, 0.9, 0.95);
    leg.AddEntry(&h, "histo");
    leg.Draw();

    c.Print("p.png");
}

and CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(leak)

find_package(ROOT 6.36.00 CONFIG REQUIRED)

include(${ROOT_USE_FILE})

add_executable(leak leak.cxx)

target_link_libraries(leak ${ROOT_LIBRARIES})

Leads to several "definitely lost" in valgrind:

valgrind --leak-check=full          --show-leak-kinds=all          --track-origins=yes          --verbose          --log-file=valgrind-out.txt --suppressions=$ROOTSYS/etc/valgrind-root.supp        ./build/leak

See:

==22380== 865 bytes in 9 blocks are definitely lost in loss record 6,294 of 6,851
==22380==    at 0x485080F: malloc (vg_replace_malloc.c:447)
==22380==    by 0x6510657: ??? (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x65149F4: ??? (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x657E5FB: ??? (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x651342A: ??? (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x6520009: FT_Glyph_To_Bitmap (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x52A22EF: TTFhandle::GetGlyphBitmap(unsigned int, bool) (TTF.cxx:264)
==22380==    by 0x27F41612: TASImage::DrawTextOnPad(TText*, int, int, TVirtualPad*, int, int) (TASImage.cxx:5823)
==22380==    by 0x27AAA495: TImageDump::Text(double, double, char const*) (TImageDump.cxx:811)
==22380==    by 0x52738D3: TLatex::Analyse(double, double, TLatex::TextSpec_t const&, char const*, int) (TLatex.cxx:1982)
==22380==    by 0x527587A: TLatex::PaintLatex1(double, double, double, double, char const*) (TLatex.cxx:2324)
==22380==    by 0x526B2D1: TLatex::Paint(char const*) (TLatex.cxx:2142)


==22380== 2,728 (360 direct, 2,368 indirect) bytes in 1 blocks are definitely lost in loss record 6,470 of 6,851
==22380==    at 0x485080F: malloc (vg_replace_malloc.c:447) 
==22380==    by 0x650E802: FT_New_Library (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x651801E: FT_Init_FreeType (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x52A19B2: TTFhandle::InitClose(int) (TTF.cxx:73)
==22380==    by 0x52A1AD5: TTFhandle::TTFhandle() (TTF.cxx:53)
==22380==    by 0x53C39F9: TPadPainterBase::GetTextAscentDescent(short, double, unsigned int&, unsigned int&, char const*) (TPadPainterBase.cxx:100)
==22380==    by 0x527367C: TLatex::Analyse(double, double, TLatex::TextSpec_t const&, char const*, int) (TLatex.cxx:1987)
==22380==    by 0x5274CE6: TLatex::Anal1(TLatex::TextSpec_t const&, char const*, int) (TLatex.cxx:540)
==22380==    by 0x5274EF3: TLatex::FirstParse(double, double, char const*) (TLatex.cxx:2560)
==22380==    by 0x52754DE: TLatex::PaintLatex1(double, double, double, double, char const*) (TLatex.cxx:2292)
==22380==    by 0x526B2D1: TLatex::Paint(char const*) (TLatex.cxx:2142)
==22380==    by 0x53BB180: TPad::Paint(char const*) (TPad.cxx:3660)


==22380== 2,728 (56 direct, 2,672 indirect) bytes in 1 blocks are definitely lost in loss record 6,471 of 6,851
==22380==    at 0x485080F: malloc (vg_replace_malloc.c:447) 
==22380==    by 0x650E89B: ??? (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x6517D9C: FT_Add_Module (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x6517FAB: FT_Add_Default_Modules (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x651802E: FT_Init_FreeType (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x52A19B2: TTFhandle::InitClose(int) (TTF.cxx:73)
==22380==    by 0x52A1AD5: TTFhandle::TTFhandle() (TTF.cxx:53)
==22380==    by 0x53C39F9: TPadPainterBase::GetTextAscentDescent(short, double, unsigned int&, unsigned int&, char const*) (TPadPainterBase.cxx:100)
==22380==    by 0x527367C: TLatex::Analyse(double, double, TLatex::TextSpec_t const&, char const*, int) (TLatex.cxx:1987)
==22380==    by 0x5274CE6: TLatex::Anal1(TLatex::TextSpec_t const&, char const*, int) (TLatex.cxx:540)
==22380==    by 0x5274EF3: TLatex::FirstParse(double, double, char const*) (TLatex.cxx:2560)
==22380==    by 0x52754DE: TLatex::PaintLatex1(double, double, double, double, char const*) (TLatex.cxx:2292)

==22380== 2,728 (360 direct, 2,368 indirect) bytes in 1 blocks are definitely lost in loss record 6,474 of 6,851
==22380==    at 0x485080F: malloc (vg_replace_malloc.c:447)
==22380==    by 0x650E802: FT_New_Library (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x651801E: FT_Init_FreeType (in /usr/lib/x86_64-linux-gnu/libfreetype.so.6.20.5)
==22380==    by 0x52A19B2: TTFhandle::InitClose(int) (TTF.cxx:73)
==22380==    by 0x52A1AD5: TTFhandle::TTFhandle() (TTF.cxx:53)
==22380==    by 0x53C39F9: TPadPainterBase::GetTextAscentDescent(short, double, unsigned int&, unsigned int&, char const*) (TPadPainterBase.cxx:100)
==22380==    by 0x527367C: TLatex::Analyse(double, double, TLatex::TextSpec_t const&, char const*, int) (TLatex.cxx:1987)
==22380==    by 0x5274CE6: TLatex::Anal1(TLatex::TextSpec_t const&, char const*, int) (TLatex.cxx:540)
==22380==    by 0x5274EF3: TLatex::FirstParse(double, double, char const*) (TLatex.cxx:2560)
==22380==    by 0x5276845: TLatex::GetYsize() (TLatex.cxx:2697)
==22380==    by 0x527B45C: TLegend::PaintPrimitives() (TLegend.cxx:662)
==22380==    by 0x53BB180: TPad::Paint(char const*) (TPad.cxx:3660)

etc

ROOT version

ROOT Version: 6.41.01
Built for linuxx8664gcc on Jul 03 2026, 16:07:36
From heads/master@v6-99-99-557-g6d98c841f

built with:
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -Dbuiltin_vdt=ON -Dbuiltin_tbb=OFF -Dxrootd=OFF -Ddavix=OFF -Dmathmore=ON

Installation method

built from source

Operating system

Ubuntu 26.04

Additional context

No response

Metadata

Metadata

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions