changeset 32917:9949f3a123cf

Add new function bpFree() to free txSamples (bitmaps). (Note: None of the systems known or tested have a problem with initializing numeric zero and pointer null as all-bits-zero.)
author ib
date Wed, 02 Mar 2011 18:14:20 +0000
parents 5fdd52feb5ea
children efb929029ec9
files gui/app.c gui/bitmap.c gui/bitmap.h gui/skin/font.c
diffstat 4 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/gui/app.c	Wed Mar 02 17:42:06 2011 +0000
+++ b/gui/app.c	Wed Mar 02 18:14:20 2011 +0000
@@ -88,12 +88,7 @@
     item->message          = 0;
     item->pressed          = btnReleased;
     item->tmp              = 0;
-    item->Bitmap.Width     = 0;
-    item->Bitmap.Height    = 0;
-    item->Bitmap.BPP       = 0;
-    item->Bitmap.ImageSize = 0;
-    free(item->Bitmap.Image);
-    item->Bitmap.Image = NULL;
+    bpFree(&item->Bitmap);
     item->fontid       = 0;
     free(item->label);
     item->label = NULL;
--- a/gui/bitmap.c	Wed Mar 02 17:42:06 2011 +0000
+++ b/gui/bitmap.c	Wed Mar 02 18:14:20 2011 +0000
@@ -206,6 +206,12 @@
     return 0;
 }
 
+void bpFree(txSample *bf)
+{
+    free(bf->Image);
+    memset(bf, 0, sizeof(*bf));
+}
+
 void Convert32to1(txSample *in, txSample *out, int adaptivlimit)
 {
     out->Width     = in->Width;
--- a/gui/bitmap.h	Wed Mar 02 17:42:06 2011 +0000
+++ b/gui/bitmap.h	Wed Mar 02 18:14:20 2011 +0000
@@ -27,6 +27,7 @@
     char *Image;
 } txSample;
 
+void bpFree(txSample *);
 int bpRead(char *, txSample *);
 void Convert32to1(txSample *, txSample *, int);
 
--- a/gui/skin/font.c	Wed Mar 02 17:42:06 2011 +0000
+++ b/gui/skin/font.c	Wed Mar 02 18:14:20 2011 +0000
@@ -65,7 +65,7 @@
 
     for (i = 0; i < MAX_FONTS; i++) {
         if (Fonts[i]) {
-            gfree((void **)&Fonts[i]->Bitmap.Image);
+            bpFree(&Fonts[i]->Bitmap);
             gfree((void **)&Fonts[i]);
         }
     }
@@ -154,7 +154,7 @@
             mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[font] image file: %s\n", tmp);
 
             if (skinBPRead(tmp, &Fonts[id]->Bitmap) != 0) {
-                gfree((void **)&Fonts[id]->Bitmap.Image);
+                bpFree(&Fonts[id]->Bitmap);
                 gfree((void **)&Fonts[id]);
                 fclose(f);
                 return -4;
@@ -287,7 +287,7 @@
     th  = fntTextHeight(id, txt);
 
     if (item->height != th)
-        gfree((void **)&item->Bitmap.Image);
+        bpFree(&item->Bitmap);
 
     if (!item->Bitmap.Image) {
         item->Bitmap.Height    = item->height = th;