[LyX/master] Avoid memory leak in dummy functions
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Tue May 12 13:43:59 UTC 2026
commit 8340ad0797f8fad619f940b69671f7b3976afa74
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Tue May 12 15:34:00 2026 +0200
Avoid memory leak in dummy functions
theLaTeXFonts/Colors() should not return a new object every time.
Spotted by Coverity.
---
src/tests/dummy4checklayout.cpp | 4 ++--
src/tex2lyx/dummy_impl.cpp | 11 +++++++----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/tests/dummy4checklayout.cpp b/src/tests/dummy4checklayout.cpp
index b15d5c1327..0a3f6bf88e 100644
--- a/src/tests/dummy4checklayout.cpp
+++ b/src/tests/dummy4checklayout.cpp
@@ -41,8 +41,8 @@ using namespace support;
LaTeXColors & theLaTeXColors()
{
- LaTeXColors * lc = new LaTeXColors;
- return * lc;
+ static LaTeXColors lc;
+ return lc;
}
//
diff --git a/src/tex2lyx/dummy_impl.cpp b/src/tex2lyx/dummy_impl.cpp
index 3214334b3e..486cb594a5 100644
--- a/src/tex2lyx/dummy_impl.cpp
+++ b/src/tex2lyx/dummy_impl.cpp
@@ -60,25 +60,28 @@ LyXRC lyxrc;
LaTeXColors & theLaTeXColors()
{
- LaTeXColors * lc = new LaTeXColors;
- return * lc;
+ static LaTeXColors lc;
+ return lc;
}
+
//
// Dummy definitions needed by Language
//
LaTeXFonts & theLaTeXFonts()
{
- LaTeXFonts * lc = new LaTeXFonts;
- return * lc;
+ static LaTeXFonts lc;
+ return lc;
}
+
LaTeXFont LaTeXFonts::getLaTeXFont(docstring const &)
{
return LaTeXFont();
}
+
bool LaTeXFont::hasFontenc(std::string const &) const
{
return false;
More information about the lyx-cvs
mailing list