]> git.imager.perl.org - imager.git/commitdiff
fix memory leaks, gif screen size calculations
authorTony Cook <tony@develop=help.com>
Thu, 1 Nov 2001 23:43:34 +0000 (23:43 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 1 Nov 2001 23:43:34 +0000 (23:43 +0000)
extra tests for some leaks

Changes
Imager.xs
gif.c
t/t105gif.t

diff --git a/Changes b/Changes
index 3e5606c8ae192e2ab4d737f446f638638d555a97..e6d6d75903cf8570c4dd8de6fa3ebe18c316a2d6 100644 (file)
--- a/Changes
+++ b/Changes
@@ -542,6 +542,7 @@ Revision history for Perl extension Imager.
           XS and perl OO code added.
         - Test for iolayer t/t07iolayer.t implemented.
        - Fixed most known memory leaks.
+       - gif screen was wasn't being calculated correctly
 
 =================================================================
 
index 290497d9b2ac18e2e4fe6039f125bc4aa7529031..885bfa7dd8c76f416a92bc38930aee197281e1f5 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -224,6 +224,8 @@ static void handle_quant_opts(i_quantize *quant, HV *hv)
   STRLEN len;
   char *str;
 
+  quant->mc_colors = mymalloc(quant->mc_size * sizeof(i_color));
+
   sv = hv_fetch(hv, "transp", 6, 0);
   if (sv && *sv && (str = SvPV(*sv, len))) {
     quant->transp = 
@@ -345,6 +347,12 @@ static void handle_quant_opts(i_quantize *quant, HV *hv)
     quant->perturb = SvIV(*sv);
 }
 
+static void cleanup_quant_opts(i_quantize *quant) {
+  myfree(quant->mc_colors);
+  if (quant->ed_map)
+    myfree(quant->ed_map);
+}
+
 /* look through the hash for options to add to opts */
 static void handle_gif_opts(i_gif_opts *opts, HV *hv)
 {
@@ -415,6 +423,17 @@ static void handle_gif_opts(i_gif_opts *opts, HV *hv)
   opts->eliminate_unused = hv_fetch_bool(hv, "gif_eliminate_unused", 1);
 }
 
+static void cleanup_gif_opts(i_gif_opts *opts) {
+  if (opts->delays)
+    myfree(opts->delays);
+  if (opts->user_input_flags)
+    myfree(opts->user_input_flags);
+  if (opts->disposal)
+    myfree(opts->disposal);
+  if (opts->positions) 
+    myfree(opts->positions);
+}
+
 /* copies the color map from the hv into the colors member of the HV */
 static void copy_colors_back(HV *hv, i_quantize *quant) {
   SV **sv;
@@ -1479,7 +1498,6 @@ i_writegif_gen(fd, ...)
        hv = (HV *)SvRV(ST(1));
        memset(&quant, 0, sizeof(quant));
        quant.mc_size = 256;
-       quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
        memset(&opts, 0, sizeof(opts));
        handle_quant_opts(&quant, hv);
        handle_gif_opts(&opts, hv);
@@ -1516,7 +1534,8 @@ i_writegif_gen(fd, ...)
         ST(0) = sv_newmortal();
         if (RETVAL == 0) ST(0)=&PL_sv_undef;
         else sv_setiv(ST(0), (IV)RETVAL);
-       myfree(quant.mc_colors);
+       cleanup_gif_opts(&opts);
+       cleanup_quant_opts(&quant);
 
 
 undef_int
@@ -1538,7 +1557,6 @@ i_writegif_callback(cb, maxbuffer,...)
        hv = (HV *)SvRV(ST(2));
        memset(&quant, 0, sizeof(quant));
        quant.mc_size = 256;
-       quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
        memset(&opts, 0, sizeof(opts));
        handle_quant_opts(&quant, hv);
        handle_gif_opts(&opts, hv);
@@ -1569,9 +1587,11 @@ i_writegif_callback(cb, maxbuffer,...)
            copy_colors_back(hv, &quant);
           }
        }
-             ST(0) = sv_newmortal();
-             if (RETVAL == 0) ST(0)=&PL_sv_undef;
-             else sv_setiv(ST(0), (IV)RETVAL);
+       ST(0) = sv_newmortal();
+       if (RETVAL == 0) ST(0)=&PL_sv_undef;
+       else sv_setiv(ST(0), (IV)RETVAL);
+       cleanup_gif_opts(&opts);
+       cleanup_quant_opts(&quant);
 
 void
 i_readgif(fd)
@@ -2402,13 +2422,12 @@ i_img_to_pal(src, quant)
         hv = (HV *)SvRV(ST(1));
         memset(&quant, 0, sizeof(quant));
         quant.mc_size = 256;
-        quant.mc_colors = mymalloc(quant.mc_size * sizeof(i_color));
        handle_quant_opts(&quant, hv);
         RETVAL = i_img_to_pal(src, &quant);
         if (RETVAL) {
           copy_colors_back(hv, &quant);
         }
-        myfree(quant.mc_colors);
+       cleanup_quant_opts(&quant);
       OUTPUT:
         RETVAL
 
diff --git a/gif.c b/gif.c
index cff679f662f9522a7147a562da29a102b5147318..bb981c73af555361184fe12ac156b451c7d8abd7 100644 (file)
--- a/gif.c
+++ b/gif.c
@@ -1342,7 +1342,7 @@ i_writegif_low(i_quantize *quant, GifFileType *gf, i_img **imgs, int count,
     if (imgn < opts->position_count) {
       if (imgs[imgn]->xsize + opts->positions[imgn].x > scrw)
        scrw = imgs[imgn]->xsize + opts->positions[imgn].x;
-      if (imgs[imgn]->ysize + opts->positions[imgn].y > scrw)
+      if (imgs[imgn]->ysize + opts->positions[imgn].y > scrh)
        scrh = imgs[imgn]->ysize + opts->positions[imgn].y;
     }
     else {
index 0e026147b3ef247e6df9ec14fbced81b1d23ab5d..a55203b6082f395edbf77aabb71a81b5ddc329fb 100644 (file)
@@ -160,6 +160,8 @@ if (!i_has_format("gif")) {
                                 translate=>'closest',
                                 gif_delays=>\@gif_delays,
                                 gif_disposal=>\@gif_disposal,
+                                gif_positions=> [ map [ $_*10, $_*10 ], 0..4 ],
+                                gif_user_input=>[ 1, 0, 1, 0, 1 ],
                                 transp=>'ordered',
                                 tr_orddith=>'dot8'}, @imgs)
       or die "Cannot write anim gif";