fix minor leaks
authorJosh Coalson <jcoalson@users.sourceforce.net>
Tue, 13 Feb 2007 02:05:19 +0000 (02:05 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Tue, 13 Feb 2007 02:05:19 +0000 (02:05 +0000)
include/share/utf8.h
src/flac/encode.c
src/share/utf8/utf8.c
src/test_libFLAC++/metadata_manip.cpp
src/test_libFLAC/metadata_manip.c
src/test_seeking/main.c

index 6aa0e98..7d6650d 100644 (file)
@@ -19,8 +19,6 @@
  *   3 : unknown encoding (but still converted, using '?')
  */
 
-void convert_set_charset(const char *charset);
-
 int utf8_encode(const char *from, char **to);
 int utf8_decode(const char *from, char **to);
 
index f760031..0b0e89d 100644 (file)
@@ -1500,7 +1500,7 @@ int flac__encode_flac(FILE *infile, off_t infilesize, const char *infilename, co
 
                /* (channel mask will get copied over from the source VORBIS_COMMENT if it exists) */
                if(!EncoderSession_init_encoder(&encoder_session, options.common, /*channel_mask=*/0, decoder_data.metadata_blocks[0]->data.stream_info.channels, decoder_data.metadata_blocks[0]->data.stream_info.bits_per_sample, decoder_data.metadata_blocks[0]->data.stream_info.sample_rate, &decoder_data))
-                       return EncoderSession_finish_error(&encoder_session);
+                       goto fubar2; /*@@@ yuck */
 
                /*
                 * have to wait until the FLAC encoder is set up for writing
@@ -1542,12 +1542,12 @@ int flac__encode_flac(FILE *infile, off_t infilesize, const char *infilename, co
        retval = EncoderSession_finish_ok(&encoder_session, -1, -1);
        /* have to wail until encoder is completely finished before deleting because of the final step of writing the seekpoint offsets */
        for(i = 0; i < decoder_data.num_metadata_blocks; i++)
-               free(decoder_data.metadata_blocks[i]);
+               FLAC__metadata_object_delete(decoder_data.metadata_blocks[i]);
        return retval;
 
 fubar2:
        for(i = 0; i < decoder_data.num_metadata_blocks; i++)
-               free(decoder_data.metadata_blocks[i]);
+               FLAC__metadata_object_delete(decoder_data.metadata_blocks[i]);
 fubar1:
        FLAC__stream_decoder_delete(decoder);
        return EncoderSession_finish_error(&encoder_session);
index a77e38b..b6f0a8a 100644 (file)
@@ -231,23 +231,17 @@ int iconvert(const char *fromcode, const char *tocode,
             const char *from, size_t fromlen,
             char **to, size_t *tolen);
 
-static char *current_charset = 0; /* means "US-ASCII" */
-
-void convert_set_charset(const char *charset)
+static const char *current_charset(void)
 {
-
+  const char *c = 0;
 #ifdef HAVE_LANGINFO_CODESET
-  if (!charset)
-    charset = nl_langinfo(CODESET);
+  c = nl_langinfo(CODESET);
 #endif
 
-  if (!charset)
-    charset = getenv("CHARSET");
+  if (!c)
+    c = getenv("CHARSET");
 
-  free(current_charset);
-  current_charset = 0;
-  if (charset && *charset)
-    current_charset = strdup(charset);
+  return c? c : "US-ASCII";
 }
 
 static int convert_buffer(const char *fromcode, const char *tocode,
@@ -300,20 +294,14 @@ int utf8_encode(const char *from, char **to)
 {
   char *charset;
 
-  if (!current_charset)
-    convert_set_charset(0);
-  charset = current_charset ? current_charset : "US-ASCII";
-  return convert_string(charset, "UTF-8", from, to, '#');
+  return convert_string(current_charset(), "UTF-8", from, to, '#');
 }
 
 int utf8_decode(const char *from, char **to)
 {
   char *charset;
 
-  if (!current_charset)
-    convert_set_charset(0);
-  charset = current_charset ? current_charset : "US-ASCII";
-  return convert_string("UTF-8", charset, from, to, '?');
+  return convert_string("UTF-8", current_charset(), from, to, '?');
 }
 
 #endif
index c996cda..b750623 100644 (file)
@@ -600,6 +600,8 @@ static bool generate_file_(bool include_extras, bool is_ogg)
                return die_("creating the encoded file");
 
        free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
+       free(picture.data.picture.mime_type);
+       free(picture.data.picture.description);
        free(picture.data.picture.data);
 
        return true;
index 8a00235..08c00ae 100644 (file)
@@ -610,6 +610,10 @@ static FLAC__bool generate_file_(FLAC__bool include_extras, FLAC__bool is_ogg)
 
        free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
        free(picture.data.picture.mime_type);
+       free(picture.data.picture.description);
+       free(picture.data.picture.data);
+       if(!include_extras)
+               FLAC__metadata_object_delete(cuesheet);
 
        return true;
 }
index 3bc0db4..1ea18ed 100644 (file)
@@ -304,6 +304,7 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
                        return die_s_("FLAC__stream_decoder_finish() FAILED", decoder);
        }
 
+       FLAC__stream_decoder_delete(decoder);
        printf("\nPASSED!\n");
 
        return true;