Memory and fd leak fixes - ID: 3436668
[platform/upstream/flac.git] / src / metaflac / operations_shorthand_picture.c
index 0146187..bc51296 100644 (file)
@@ -1,5 +1,5 @@
 /* metaflac - Command-line FLAC metadata editor
- * Copyright (C) 2001,2002,2003,2004,2005,2006,2007  Josh Coalson
+ * Copyright (C) 2001,2002,2003,2004,2005,2006,2007,2008,2009  Josh Coalson
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -27,6 +27,8 @@
 #include "FLAC/assert.h"
 #include "share/grabbag.h" /* for grabbag__picture_parse_specification() etc */
 
+#include "operations_shorthand.h"
+
 static FLAC__bool import_pic_from(const char *filename, FLAC__StreamMetadata **picture, const char *specification, FLAC__bool *needs_write);
 static FLAC__bool export_pic_to(const char *filename, const FLAC__StreamMetadata *picture, const char *pic_filename);
 
@@ -161,6 +163,8 @@ FLAC__bool export_pic_to(const char *filename, const FLAC__StreamMetadata *pictu
 
        if(fwrite(picture->data.picture.data, 1, len, f) != len) {
                fprintf(stderr, "%s: ERROR: writing PICTURE data to file\n", filename);
+               if(f != stdout)
+                       fclose(f);
                return false;
        }