[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] GSoC-2019-moazin c9308ac 23/32: Do proper memory freeing to
From: |
Moazin Khatti |
Subject: |
[freetype2] GSoC-2019-moazin c9308ac 23/32: Do proper memory freeing to prevent leaks. |
Date: |
Thu, 11 Jul 2019 05:10:06 -0400 (EDT) |
branch: GSoC-2019-moazin
commit c9308ac1715da52ffe40cb59562088ddbe67ae25
Author: Moazin Khatti <address@hidden>
Commit: Moazin Khatti <address@hidden>
Do proper memory freeing to prevent leaks.
* include/freetype/internal/ftobjs.h: Create a new flag named
`FT_GLYPH_OWN_GZIP_SVG' to indicate that `svg_document' in
`slot->other' is GZIP compressed and has to be freed later.
* src/base/ftglyph.c: Minor styling.
* src/base/ftobjs.c: Add code to free memory that was previously
allocated for storing GZIP compressed SVG documents.
* src/sfnt/ttsvg.c: Set the `FT_GLYPH_OWN_GZIP_SVG' flag if the
document is GZIP compressed.
---
include/freetype/internal/ftobjs.h | 3 ++-
src/base/ftglyph.c | 8 ++++++--
src/base/ftobjs.c | 18 ++++++++++++++++++
src/sfnt/ttsvg.c | 3 ++-
4 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/include/freetype/internal/ftobjs.h
b/include/freetype/internal/ftobjs.h
index 0c1d3e5..2f20509 100644
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -418,7 +418,8 @@ FT_BEGIN_HEADER
* initializing the glyph slot.
*/
-#define FT_GLYPH_OWN_BITMAP 0x1U
+#define FT_GLYPH_OWN_BITMAP 0x1U
+#define FT_GLYPH_OWN_GZIP_SVG 0x2U
typedef struct FT_Slot_InternalRec_
{
diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c
index 19a170c..0954695 100644
--- a/src/base/ftglyph.c
+++ b/src/base/ftglyph.c
@@ -378,10 +378,13 @@
target->metrics = source->metrics;
/* allocate space for the svg document */
- target->svg_document = memory->alloc( memory, target->svg_document_length
);
+ target->svg_document = memory->alloc( memory,
+ target->svg_document_length );
/* copy the stuff */
- FT_MEM_COPY( target->svg_document, source->svg_document,
target->svg_document_length );
+ FT_MEM_COPY( target->svg_document,
+ source->svg_document,
+ target->svg_document_length );
return error;
}
@@ -396,6 +399,7 @@
FT_SVG_Document document;
+ /* TODO: (OT-SVG) this probably creates a memory leak. Fix it */
if ( FT_NEW( document ) )
return error;
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 49b63bd..871e4be 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -561,8 +561,19 @@
slot->subglyphs = NULL;
slot->control_data = NULL;
slot->control_len = 0;
+
if ( !( slot->face->face_flags & FT_FACE_FLAG_SVG ) )
slot->other = NULL;
+ {
+ if ( slot->internal->flags & FT_GLYPH_OWN_GZIP_SVG )
+ {
+ FT_Memory memory = slot->face->memory;
+ FT_SVG_Document doc = (FT_SVG_Document)slot->other;
+ FT_FREE( doc->svg_document );
+ slot->internal->load_flags &= ~FT_GLYPH_OWN_GZIP_SVG;
+ }
+ }
+
slot->format = FT_GLYPH_FORMAT_NONE;
slot->linearHoriAdvance = 0;
@@ -582,6 +593,13 @@
if ( slot->face->face_flags & FT_FACE_FLAG_SVG )
{
+ /* free memory in case svg was there */
+ if ( slot->internal->flags & FT_GLYPH_OWN_GZIP_SVG )
+ {
+ FT_SVG_Document doc = (FT_SVG_Document)slot->other;
+ FT_FREE( doc->svg_document );
+ slot->internal->flags &= ~FT_GLYPH_OWN_GZIP_SVG;
+ }
FT_FREE( slot->other );
}
diff --git a/src/sfnt/ttsvg.c b/src/sfnt/ttsvg.c
index 4ec3b2d..d9ad75a 100644
--- a/src/sfnt/ttsvg.c
+++ b/src/sfnt/ttsvg.c
@@ -26,6 +26,7 @@
#include <ft2build.h>
#include FT_INTERNAL_STREAM_H
+#include FT_INTERNAL_OBJECTS_H
#include FT_TRUETYPE_TAGS_H
#include FT_GZIP_H
#include FT_SVG_RENDERER_H
@@ -214,8 +215,8 @@
(FT_ULong)doc_list[doc_length - 3] << 8 |
(FT_ULong)doc_list[doc_length - 4];
- /* TODO: (OT-SVG) memory allocated here needs to be freed somewhere */
uncomp_buffer = (FT_Byte*) memory->alloc(memory, uncomp_size);
+ glyph->internal->flags |= FT_GLYPH_OWN_GZIP_SVG;
error = FT_Gzip_Uncompress( memory, uncomp_buffer, &uncomp_size,
doc_list, doc_length );
if ( error != FT_Err_Ok )
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] GSoC-2019-moazin c9308ac 23/32: Do proper memory freeing to prevent leaks.,
Moazin Khatti <=