[Libreoffice-commits] core.git: include/vcl vcl/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Tue May 11 09:14:51 UTC 2021
include/vcl/glyphitem.hxx | 7 ++++---
vcl/source/gdi/impglyphitem.cxx | 37 +++++++++++++------------------------
2 files changed, 17 insertions(+), 27 deletions(-)
New commits:
commit adfd91d24678053b9a1475ad6985eb1fc548706a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon May 10 20:17:11 2021 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue May 11 11:14:05 2021 +0200
fix leak in SalLayoutGlyphs
we forgot to delete the extra impls vector
Also make more use of std::unique_ptr
Change-Id: I2c745c0ad2b7ad62d368e9702bd2c32c734442fc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115375
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/vcl/glyphitem.hxx b/include/vcl/glyphitem.hxx
index d928bb954ee7..68f89701b2c3 100644
--- a/include/vcl/glyphitem.hxx
+++ b/include/vcl/glyphitem.hxx
@@ -24,6 +24,7 @@
#include <vcl/dllapi.h>
#include <vector>
+#include <memory>
typedef sal_uInt16 sal_GlyphId;
@@ -31,14 +32,14 @@ class SalLayoutGlyphsImpl;
class VCL_DLLPUBLIC SalLayoutGlyphs final
{
- SalLayoutGlyphsImpl* m_pImpl = nullptr;
+ std::unique_ptr<SalLayoutGlyphsImpl> m_pImpl;
// Extra items are in a dynamically allocated vector in order to save memory.
// The usual case should be that this stays unused (it should be only used
// when font fallback takes place).
- std::vector<SalLayoutGlyphsImpl*>* m_pExtraImpls = nullptr;
+ std::unique_ptr<std::vector<std::unique_ptr<SalLayoutGlyphsImpl>>> m_pExtraImpls;
public:
- SalLayoutGlyphs() = default;
+ SalLayoutGlyphs();
SalLayoutGlyphs(const SalLayoutGlyphs&) = delete;
SalLayoutGlyphs(SalLayoutGlyphs&&);
~SalLayoutGlyphs();
diff --git a/vcl/source/gdi/impglyphitem.cxx b/vcl/source/gdi/impglyphitem.cxx
index 35681c341ea1..e9d5e699356c 100644
--- a/vcl/source/gdi/impglyphitem.cxx
+++ b/vcl/source/gdi/impglyphitem.cxx
@@ -23,13 +23,9 @@
#include <unx/freetype_glyphcache.hxx>
#endif
-SalLayoutGlyphs::~SalLayoutGlyphs()
-{
- delete m_pImpl;
- if (m_pExtraImpls)
- for (SalLayoutGlyphsImpl* impl : *m_pExtraImpls)
- delete impl;
-}
+SalLayoutGlyphs::SalLayoutGlyphs() {}
+
+SalLayoutGlyphs::~SalLayoutGlyphs() {}
SalLayoutGlyphs::SalLayoutGlyphs(SalLayoutGlyphs&& rOther)
{
@@ -54,7 +50,7 @@ bool SalLayoutGlyphs::IsValid() const
if (!m_pImpl->IsValid())
return false;
if (m_pExtraImpls)
- for (SalLayoutGlyphsImpl* impl : *m_pExtraImpls)
+ for (std::unique_ptr<SalLayoutGlyphsImpl> const& impl : *m_pExtraImpls)
if (!impl->IsValid())
return false;
return true;
@@ -63,35 +59,28 @@ bool SalLayoutGlyphs::IsValid() const
void SalLayoutGlyphs::Invalidate()
{
// Invalidating is in fact simply clearing.
- delete m_pImpl;
- m_pImpl = nullptr;
- if (m_pExtraImpls)
- {
- for (SalLayoutGlyphsImpl* impl : *m_pExtraImpls)
- delete impl;
- delete m_pExtraImpls;
- m_pExtraImpls = nullptr;
- }
+ m_pImpl.reset();
+ m_pExtraImpls.reset();
}
SalLayoutGlyphsImpl* SalLayoutGlyphs::Impl(unsigned int nLevel) const
{
if (nLevel == 0)
- return m_pImpl;
+ return m_pImpl.get();
if (m_pExtraImpls != nullptr && nLevel - 1 < m_pExtraImpls->size())
- return (*m_pExtraImpls)[nLevel - 1];
+ return (*m_pExtraImpls)[nLevel - 1].get();
return nullptr;
}
void SalLayoutGlyphs::AppendImpl(SalLayoutGlyphsImpl* pImpl)
{
- if (m_pImpl == nullptr)
- m_pImpl = pImpl;
+ if (!m_pImpl)
+ m_pImpl.reset(pImpl);
else
{
- if (m_pExtraImpls == nullptr)
- m_pExtraImpls = new std::vector<SalLayoutGlyphsImpl*>;
- m_pExtraImpls->push_back(pImpl);
+ if (!m_pExtraImpls)
+ m_pExtraImpls.reset(new std::vector<std::unique_ptr<SalLayoutGlyphsImpl>>);
+ m_pExtraImpls->emplace_back(pImpl);
}
}
More information about the Libreoffice-commits
mailing list