[prev in list] [next in list] [prev in thread] [next in thread]
List: xine-cvslog
Subject: [xine-cvs] =?utf-8?q?HG=3A_xine-lib-1=2E2=3A_goom=3A_fix_leaks_?= =?utf-8?q?=28fonts=29?=
From: Petri_Hintukainen via Xine-cvslog <xine-cvslog () lists ! sourceforge ! net
Date: 2017-09-30 12:57:46
Message-ID: 964ce3b7620e43ffddde.1506776151 () hg ! debian ! org
[Download RAW message or body]
# HG changeset patch
# User Petri Hintukainen <phintuka@users.sourceforge.net>
# Date 1506776151 -10800
# Node ID 964ce3b7620e43ffddde8a9e6cdbbac98b87fc50
# Branch default
# Parent 4fb0266862be2b740c7de35954b2c036823b5f16
goom: fix leaks (fonts)
Fonts were stored in static pointers and loaded multiple times.
Data was allocated multiple times, never freed.
diff --git a/src/post/goom/gfontlib.c b/src/post/goom/gfontlib.c
--- a/src/post/goom/gfontlib.c
+++ b/src/post/goom/gfontlib.c
@@ -4,22 +4,61 @@
#include <string.h>
#include <stdlib.h>
-static Pixel ***font_chars;
-static int *font_width;
-static int *font_height;
-static Pixel ***small_font_chars;
-static int *small_font_width;
-static int *small_font_height;
+struct goomfont_s {
+ Pixel ***font_chars;
+ int *font_width;
+ int *font_height;
+ Pixel ***small_font_chars;
+ int *small_font_width;
+ int *small_font_height;
+};
-void gfont_load (void) {
+void gfont_unload(goomfont_t **pp)
+{
+ if (*pp) {
+ goomfont_t *p = *pp;
+ int i, y;
+
+ for (i = 0; i < 256; i++) {
+ if (p->font_chars[i] && (i == 42 || p->font_chars[i] != \
p->font_chars[42])) { + for (y = 0; y < p->font_height[i]; y++) {
+ free(p->font_chars[i][y]);
+ }
+ free(p->font_chars[i]);
+ }
+ if (p->small_font_chars[i] && (i == 42 || p->small_font_chars[i] != \
p->small_font_chars[42])) { + for (y = 0; y < p->font_height[i]/2; y++) {
+ free(p->small_font_chars[i][y]);
+ }
+ free(p->small_font_chars[i]);
+ }
+ }
+
+ free(p->font_chars);
+ free(p->small_font_chars);
+ free(p->font_width);
+ free(p->small_font_width);
+ free(p->font_height);
+ free(p->small_font_height);
+ memset(p, 0, sizeof(*p));
+
+ free(p);
+ *pp = NULL;
+ }
+}
+
+goomfont_t *gfont_load (void) {
unsigned char *gfont;
unsigned int i = 0, j = 0;
unsigned int nba = 0;
unsigned int current = 32;
int *font_pos;
+ goomfont_t *p;
/* decompress le rle */
-
+ p = calloc(1, sizeof(*p));
+ if (!p)
+ return NULL;
gfont = malloc (the_font.width*the_font.height*the_font.bytes_per_pixel);
while (i<the_font.rle_size) {
@@ -35,12 +74,12 @@
/* determiner les positions de chaque lettre. */
- font_height = calloc (256,sizeof(int));
- small_font_height = calloc (256,sizeof(int));
- font_width = calloc (256,sizeof(int));
- small_font_width = calloc (256,sizeof(int));
- font_chars = calloc (256,sizeof(int**));
- small_font_chars = calloc (256,sizeof(int**));
+ p->font_height = calloc (256,sizeof(int));
+ p->small_font_height = calloc (256,sizeof(int));
+ p->font_width = calloc (256,sizeof(int));
+ p->small_font_width = calloc (256,sizeof(int));
+ p->font_chars = calloc (256,sizeof(int**));
+ p->small_font_chars = calloc (256,sizeof(int**));
font_pos = calloc (256,sizeof(int));
for (i=0;i<the_font.width;i++) {
@@ -50,38 +89,38 @@
else
nba = 0;
if (nba == 2) {
- font_width [current] = i - font_pos [current];
- small_font_width [current] = font_width [current]/2;
- font_pos [++current] = i;
- font_height [current] = the_font.height - 2;
- small_font_height [current] = font_height [current]/2;
+ p->font_width [current] = i - font_pos [current];
+ p->small_font_width [current] = p->font_width [current]/2;
+ font_pos [++current] = i;
+ p->font_height [current] = the_font.height - 2;
+ p->small_font_height [current] = p->font_height [current]/2;
}
}
font_pos [current] = 0;
- font_height [current] = 0;
- small_font_height [current] = 0;
+ p->font_height [current] = 0;
+ p->small_font_height [current] = 0;
/* charger les lettres et convertir au format de la machine */
for (i=33;i<current;i++) {
int x; int y;
- font_chars [i] = malloc (font_height[i]*sizeof(int *));
- small_font_chars [i] = malloc (font_height[i]*sizeof(int *)/2);
- for (y = 0; y < font_height[i]; y++) {
- font_chars [i][y] = malloc (font_width[i]*sizeof(int));
- for (x = 0; x < font_width[i]; x++) {
+ p->font_chars [i] = malloc (p->font_height[i]*sizeof(int *));
+ p->small_font_chars [i] = malloc (p->font_height[i]*sizeof(int \
*)/2); + for (y = 0; y < p->font_height[i]; y++) {
+ p->font_chars [i][y] = malloc (p->font_width[i]*sizeof(int));
+ for (x = 0; x < p->font_width[i]; x++) {
unsigned int r,g,b,a;
r = gfont[(y+2)*(the_font.width*4)+(x*4+font_pos[i]*4)];
g = gfont[(y+2)*(the_font.width*4)+(x*4+font_pos[i]*4+1)];
b = gfont[(y+2)*(the_font.width*4)+(x*4+font_pos[i]*4+2)];
a = gfont[(y+2)*(the_font.width*4)+(x*4+font_pos[i]*4+3)];
- font_chars [i][y][x].val =
+ p->font_chars [i][y][x].val =
\
(r<<(ROUGE*8))|(g<<(VERT*8))|(b<<(BLEU*8))|(a<<(ALPHA*8)); }
}
- for (y = 0; y < font_height[i]/2; y++) {
- small_font_chars [i][y] = malloc (font_width[i]*sizeof(int)/2);
- for (x = 0; x < font_width[i]/2; x++) {
+ for (y = 0; y < p->font_height[i]/2; y++) {
+ p->small_font_chars [i][y] = malloc \
(p->font_width[i]*sizeof(int)/2); + for (x = 0; x < \
p->font_width[i]/2; x++) {
unsigned int \
r1,g1,b1,a1,r2,g2,b2,a2,r3,g3,b3,a3,r4,g4,b4,a4;
r1 = gfont[2*(y+1)*(the_font.width*4)+(x*8+font_pos[i]*4)];
g1 = \
gfont[2*(y+1)*(the_font.width*4)+(x*8+font_pos[i]*4+1)]; @@ -99,7 +138,7 @@
g4 = \
gfont[2*(y+1)*(the_font.width*4)+(x*8+font_pos[i]*4+5)];
b4 = \
gfont[2*(y+1)*(the_font.width*4)+(x*8+font_pos[i]*4+6)];
a4 = \
gfont[2*(y+1)*(the_font.width*4)+(x*8+font_pos[i]*4+7)];
- small_font_chars [i][y][x].val =
+ p->small_font_chars [i][y][x].val =
(((r1 + r2 + r3 + r4)>>2)<<(ROUGE*8))|
(((g1 + g2 + g3 + g4)>>2)<<(VERT*8))|
(((b1 + b2 + b3 + b4)>>2)<<(BLEU*8))|
@@ -111,28 +150,31 @@
/* definir les lettres restantes */
for (i=0;i<256;i++) {
- if (font_chars[i]==0) {
- font_chars[i]=font_chars[42];
- small_font_chars[i]=small_font_chars[42];
- font_width[i]=font_width[42];
- font_pos[i]=font_pos[42];
- font_height[i]=font_height[42];
- small_font_width[i]=small_font_width[42];
- small_font_height[i]=small_font_height[42];
- }
+ if (p->font_chars[i] == 0) {
+ p->font_chars[i] = p->font_chars[42];
+ p->small_font_chars[i] = p->small_font_chars[42];
+ p->font_width[i] = p->font_width[42];
+ font_pos[i] = font_pos[42];
+ p->font_height[i] = p->font_height[42];
+ p->small_font_width[i] = p->small_font_width[42];
+ p->small_font_height[i] = p->small_font_height[42];
+ }
}
- font_width [32] = (the_font.height / 2) - 1;
- small_font_width [32] = font_width [32]/2;
- font_chars [32] = 0;
- small_font_chars [32] = 0;
+ // XXX free it ???
+ p->font_width [32] = (the_font.height / 2) - 1;
+ p->small_font_width [32] = p->font_width [32]/2;
+ p->font_chars [32] = 0;
+ p->small_font_chars [32] = 0;
free(font_pos);
free(gfont);
+
+ return p;
}
-void goom_draw_text (Pixel * buf,int resolx,int resoly,
- int x, int y,
- const char *str, float charspace, int center) {
+void goom_draw_text (goomfont_t *p, Pixel * buf,int resolx,int resoly,
+ int x, int y,
+ const char *str, float charspace, int center) {
float fx = (float) x;
int fin = 0;
@@ -143,16 +185,16 @@
if (resolx>320)
{
/* printf("use big\n"); */
- cur_font_chars = font_chars;
- cur_font_width = font_width;
- cur_font_height = font_height;
+ cur_font_chars = p->font_chars;
+ cur_font_width = p->font_width;
+ cur_font_height = p->font_height;
}
else
{
/* printf ("use small\n"); */
- cur_font_chars = small_font_chars;
- cur_font_width = small_font_width;
- cur_font_height = small_font_height;
+ cur_font_chars = p->small_font_chars;
+ cur_font_width = p->small_font_width;
+ cur_font_height = p->small_font_height;
}
if (cur_font_chars == NULL)
--git a/src/post/goom/gfontlib.h b/src/post/goom/gfontlib.h
--- a/src/post/goom/gfontlib.h
+++ b/src/post/goom/gfontlib.h
@@ -3,8 +3,12 @@
#include "goom_graphic.h"
-void gfont_load (void);
-void goom_draw_text (Pixel * buf,int resolx,int resoly, int x, int y,
- const char *str, float chspace, int center);
+typedef struct goomfont_s goomfont_t;
+
+goomfont_t *gfont_load (void);
+void gfont_unload (goomfont_t **);
+
+void goom_draw_text (goomfont_t *, Pixel * buf, int resolx, int resoly, int x, int \
y, + const char *str, float chspace, int center);
#endif
--git a/src/post/goom/goom_core.c b/src/post/goom/goom_core.c
--- a/src/post/goom/goom_core.c
+++ b/src/post/goom/goom_core.c
@@ -103,7 +103,7 @@
GML_HLINE, 0, GML_BLACK,
GML_CIRCLE, 0.2f * (float) \
goomInfo->screen.height, GML_RED);
- gfont_load ();
+ goomInfo->font = gfont_load ();
/* goom_set_main_script(goomInfo, goomInfo->main_script_str); */
@@ -618,7 +618,7 @@
if (fps > 0) {
sprintf (text, "%2.0f fps", fps);
- goom_draw_text \
(goomInfo->p1,goomInfo->screen.width,goomInfo->screen.height, + \
goom_draw_text (goomInfo->font, \
goomInfo->p1,goomInfo->screen.width,goomInfo->screen.height, 10, 24, text, 1, 0);
}
@@ -632,12 +632,12 @@
}
if (goomInfo->update.timeOfTitleDisplay) {
- goom_draw_text \
(goomInfo->p1,goomInfo->screen.width,goomInfo->screen.height, + \
goom_draw_text (goomInfo->font, \
goomInfo->p1,goomInfo->screen.width,goomInfo->screen.height,
goomInfo->screen.width / 2, goomInfo->screen.height \
/ 2 + 7, goomInfo->update.titleText,
((float) (190 - goomInfo->update.timeOfTitleDisplay) \
/ 10.0f), 1); goomInfo->update.timeOfTitleDisplay--;
if (goomInfo->update.timeOfTitleDisplay < 4)
- goom_draw_text \
(goomInfo->p2,goomInfo->screen.width,goomInfo->screen.height, + \
goom_draw_text (goomInfo->font, \
goomInfo->p2,goomInfo->screen.width,goomInfo->screen.height,
goomInfo->screen.width / 2, \
goomInfo->screen.height / 2 + 7, goomInfo->update.titleText,
((float) (190 - \
goomInfo->update.timeOfTitleDisplay) / 10.0f), 1); }
@@ -778,6 +778,8 @@
if (goomInfo->main_scanner)
gsl_free(goomInfo->main_scanner);
+ gfont_unload(&goomInfo->font);
+
free(goomInfo->params);
free(goomInfo->visuals);
free(goomInfo->sound.params.params);
@@ -890,7 +892,7 @@
pos = (int)goomInfo->screen.height / 2;
pos += 7;
- goom_draw_text(goomInfo->p1,goomInfo->screen.width,goomInfo->screen.height,
+ goom_draw_text(goomInfo->font, \
goomInfo->p1,goomInfo->screen.width,goomInfo->screen.height, \
goomInfo->screen.width/2, pos, message,
ecart,
--git a/src/post/goom/goom_plugin_info.h b/src/post/goom/goom_plugin_info.h
--- a/src/post/goom/goom_plugin_info.h
+++ b/src/post/goom/goom_plugin_info.h
@@ -99,6 +99,8 @@
VisualFX tentacles_fx;
VisualFX ifs_fx;
+ struct goomfont_s *font;
+
/** image buffers */
guint32 *pixel;
guint32 *back;
--git a/src/post/goom/xine_goom.c b/src/post/goom/xine_goom.c
--- a/src/post/goom/xine_goom.c
+++ b/src/post/goom/xine_goom.c
@@ -57,7 +57,7 @@
#define GOOM_HEIGHT 240
/* colorspace conversion methods */
-static const char* goom_csc_methods[]={
+static const char* const goom_csc_methods[]={
"Fast but not photorealistic",
"Slow but looks better",
"Mostly fast and good quality",
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Xine-cvslog mailing list
Xine-cvslog@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xine-cvslog
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic