From 24ba370c974cf63f741f4295706a80122631ff82ff65464888ba218f50598b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= Date: Fri, 27 Jan 2012 18:52:26 +0000 Subject: [PATCH] Accepting request 101855 from home:elvigia:branches:multimedia:libs - Fix some memory and resources leak. - Link shared libraries with -Bsymbolic-functions - annotate relevant functions with proper attributes to allow the compiler generate better code (attribute hot. alloc_size) OBS-URL: https://build.opensuse.org/request/show/101855 OBS-URL: https://build.opensuse.org/package/show/multimedia:libs/flac?expand=0&rev=21 --- flac-leaks.patch | 70 ++++++++++++++ flac-visibility.patch | 217 +++++++++++++++++++++++++++++++++++++++++- flac.changes | 8 ++ flac.spec | 4 +- 4 files changed, 295 insertions(+), 4 deletions(-) create mode 100644 flac-leaks.patch diff --git a/flac-leaks.patch b/flac-leaks.patch new file mode 100644 index 0000000..4ac0136 --- /dev/null +++ b/flac-leaks.patch @@ -0,0 +1,70 @@ +--- src/libFLAC/metadata_iterators.c.orig ++++ src/libFLAC/metadata_iterators.c +@@ -1217,6 +1217,7 @@ static FLAC__bool chain_read_cb_(FLAC__M + } + + if(!read_metadata_block_header_cb_(handle, read_cb, &is_last, &type, &length)) { ++ node_delete_(node); + chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR; + return false; + } +@@ -1412,11 +1413,13 @@ static FLAC__bool chain_rewrite_file_(FL + if(!open_tempfile_(chain->filename, tempfile_path_prefix, &tempfile, &tempfilename, &status)) { + chain->status = get_equivalent_status_(status); + cleanup_tempfile_(&tempfile, &tempfilename); ++ fclose(f); + return false; + } + if(!copy_n_bytes_from_file_(f, tempfile, chain->first_offset, &status)) { + chain->status = get_equivalent_status_(status); + cleanup_tempfile_(&tempfile, &tempfilename); ++ fclose(f); + return false; + } + +@@ -1424,10 +1427,14 @@ static FLAC__bool chain_rewrite_file_(FL + for(node = chain->head; node; node = node->next) { + if(!write_metadata_block_header_(tempfile, &status, node->data)) { + chain->status = get_equivalent_status_(status); ++ cleanup_tempfile_(&tempfile, &tempfilename); ++ fclose(f); + return false; + } + if(!write_metadata_block_data_(tempfile, &status, node->data)) { + chain->status = get_equivalent_status_(status); ++ cleanup_tempfile_(&tempfile, &tempfilename); ++ fclose(f); + return false; + } + } +@@ -1437,10 +1444,12 @@ static FLAC__bool chain_rewrite_file_(FL + if(0 != fseeko(f, chain->last_offset, SEEK_SET)) { + cleanup_tempfile_(&tempfile, &tempfilename); + chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR; ++ fclose(f); + return false; + } + if(!copy_remaining_bytes_from_file_(f, tempfile, &status)) { + cleanup_tempfile_(&tempfile, &tempfilename); ++ fclose(f); + chain->status = get_equivalent_status_(status); + return false; + } +--- src/libFLAC/stream_encoder.c.orig ++++ src/libFLAC/stream_encoder.c +@@ -1004,10 +1004,12 @@ static FLAC__StreamEncoderInitStatus ini + /* + * Now set up a stream decoder for verification + */ +- encoder->private_->verify.decoder = FLAC__stream_decoder_new(); + if(0 == encoder->private_->verify.decoder) { +- encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR; +- return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; ++ encoder->private_->verify.decoder = FLAC__stream_decoder_new(); ++ if(0 == encoder->private_->verify.decoder) { ++ encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR; ++ return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; ++ } + } + + if(FLAC__stream_decoder_init_stream(encoder->private_->verify.decoder, verify_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, verify_write_callback_, verify_metadata_callback_, verify_error_callback_, /*client_data=*/encoder) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { diff --git a/flac-visibility.patch b/flac-visibility.patch index acd820f..a8b4be6 100644 --- a/flac-visibility.patch +++ b/flac-visibility.patch @@ -36,7 +36,7 @@ endif # see 'http://www.gnu.org/software/libtool/manual.html#Libtool-versioning' for numbering convention -libFLAC_la_LDFLAGS = -version-info 10:0:2 -lm $(LOCAL_EXTRA_LDFLAGS) -+libFLAC_la_LDFLAGS = -no-undefined -version-info 10:0:2 -lm $(LOCAL_EXTRA_LDFLAGS) ++libFLAC_la_LDFLAGS = -Wl,-Bsymbolic-functions -no-undefined -version-info 10:0:2 -lm $(LOCAL_EXTRA_LDFLAGS) libFLAC_la_SOURCES = \ bitmath.c \ bitreader.c \ @@ -49,13 +49,23 @@ +libFLAC___la_CXXFLAGS= -fvisibility=hidden -fvisibility-inlines-hidden # see 'http://www.gnu.org/software/libtool/manual.html#Libtool-versioning' for numbering convention -libFLAC___la_LDFLAGS = -version-info 8:0:2 -+libFLAC___la_LDFLAGS = -no-undefined -version-info 8:0:2 ++libFLAC___la_LDFLAGS = -Wl,-Bsymbolic-functions -no-undefined -version-info 8:0:2 libFLAC___la_LIBADD = ../libFLAC/libFLAC.la libFLAC___la_SOURCES = \ --- configure.in.orig +++ configure.in -@@ -28,19 +28,20 @@ AM_MAINTAINER_MODE +@@ -18,7 +18,8 @@ + # NOTE that for many of the AM_CONDITIONALs we use the prefix FLaC__ + # instead of FLAC__ since autoconf triggers off 'AC_' in strings + +-AC_INIT(src/flac/main.c) ++AC_INIT ++AC_CONFIG_SRCDIR([src/flac/main.c]) + AM_INIT_AUTOMAKE(flac, 1.2.1) + + # Don't automagically regenerate autoconf/automake generated files unless +@@ -28,23 +29,24 @@ AM_MAINTAINER_MODE # We need two libtools, one that builds both shared and static, and # one that builds only static. This is because the resulting libtool # does not allow us to choose which to build at runtime. @@ -81,6 +91,138 @@ AC_CHECK_SIZEOF(void*,0) #@@@ new name is AC_CONFIG_HEADERS +-AM_CONFIG_HEADER(config.h) ++AC_CONFIG_HEADERS([config.h]) + + AC_C_BIGENDIAN + +@@ -110,7 +112,7 @@ AC_DEFINE(FLAC__ALIGN_MALLOC_DATA) + AH_TEMPLATE(FLAC__ALIGN_MALLOC_DATA, [define to align allocated memory on 32-byte boundaries]) + fi + +-AC_ARG_ENABLE(asm-optimizations, AC_HELP_STRING([--disable-asm-optimizations], [Don't use any assembly optimization routines]), asm_opt=no, asm_opt=yes) ++AC_ARG_ENABLE(asm-optimizations, AS_HELP_STRING([--disable-asm-optimizations],[Don't use any assembly optimization routines]), asm_opt=no, asm_opt=yes) + AM_CONDITIONAL(FLaC__NO_ASM, test "x$asm_opt" = xno) + if test "x$asm_opt" = xno ; then + AC_DEFINE(FLAC__NO_ASM) +@@ -118,7 +120,7 @@ AH_TEMPLATE(FLAC__NO_ASM, [define to dis + fi + + AC_ARG_ENABLE(debug, +-AC_HELP_STRING([--enable-debug], [Turn on debugging]), ++AS_HELP_STRING([--enable-debug],[Turn on debugging]), + [case "${enableval}" in + yes) debug=true ;; + no) debug=false ;; +@@ -127,7 +129,7 @@ esac],[debug=false]) + AM_CONDITIONAL(DEBUG, test "x$debug" = xtrue) + + AC_ARG_ENABLE(sse, +-AC_HELP_STRING([--enable-sse], [Enable SSE support by asserting that the OS supports SSE instructions]), ++AS_HELP_STRING([--enable-sse],[Enable SSE support by asserting that the OS supports SSE instructions]), + [case "${enableval}" in + yes) sse_os=true ;; + no) sse_os=false ;; +@@ -140,7 +142,7 @@ AH_TEMPLATE(FLAC__SSE_OS, [define if you + fi + + AC_ARG_ENABLE(3dnow, +-AC_HELP_STRING([--disable-3dnow], [Disable 3DNOW! optimizations]), ++AS_HELP_STRING([--disable-3dnow],[Disable 3DNOW! optimizations]), + [case "${enableval}" in + yes) use_3dnow=true ;; + no) use_3dnow=false ;; +@@ -153,7 +155,7 @@ AH_TEMPLATE(FLAC__USE_3DNOW, [define to + fi + + AC_ARG_ENABLE(altivec, +-AC_HELP_STRING([--disable-altivec], [Disable Altivec optimizations]), ++AS_HELP_STRING([--disable-altivec],[Disable Altivec optimizations]), + [case "${enableval}" in + yes) use_altivec=true ;; + no) use_altivec=false ;; +@@ -166,14 +168,14 @@ AH_TEMPLATE(FLAC__USE_ALTIVEC, [define t + fi + + AC_ARG_ENABLE(thorough-tests, +-AC_HELP_STRING([--disable-thorough-tests], [Disable thorough (long) testing, do only basic tests]), ++AS_HELP_STRING([--disable-thorough-tests],[Disable thorough (long) testing, do only basic tests]), + [case "${enableval}" in + yes) thorough_tests=true ;; + no) thorough_tests=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-thorough-tests) ;; + esac],[thorough_tests=true]) + AC_ARG_ENABLE(exhaustive-tests, +-AC_HELP_STRING([--enable-exhaustive-tests], [Enable exhaustive testing (VERY long)]), ++AS_HELP_STRING([--enable-exhaustive-tests],[Enable exhaustive testing (VERY long)]), + [case "${enableval}" in + yes) exhaustive_tests=true ;; + no) exhaustive_tests=false ;; +@@ -189,7 +191,7 @@ fi + AC_SUBST(FLAC__TEST_LEVEL) + + AC_ARG_ENABLE(valgrind-testing, +-AC_HELP_STRING([--enable-valgrind-testing], [Run all tests inside Valgrind]), ++AS_HELP_STRING([--enable-valgrind-testing],[Run all tests inside Valgrind]), + [case "${enableval}" in + yes) FLAC__TEST_WITH_VALGRIND=yes ;; + no) FLAC__TEST_WITH_VALGRIND=no ;; +@@ -198,7 +200,7 @@ esac],[FLAC__TEST_WITH_VALGRIND=no]) + AC_SUBST(FLAC__TEST_WITH_VALGRIND) + + AC_ARG_ENABLE(doxygen-docs, +-AC_HELP_STRING([--disable-doxygen-docs], [Disable API documentation building via Doxygen]), ++AS_HELP_STRING([--disable-doxygen-docs],[Disable API documentation building via Doxygen]), + [case "${enableval}" in + yes) enable_doxygen_docs=true ;; + no) enable_doxygen_docs=false ;; +@@ -210,7 +212,7 @@ fi + AM_CONDITIONAL(FLaC__HAS_DOXYGEN, test -n "$DOXYGEN") + + AC_ARG_ENABLE(local-xmms-plugin, +-AC_HELP_STRING([--enable-local-xmms-plugin], [Install XMMS plugin to ~/.xmms/Plugins instead of system location]), ++AS_HELP_STRING([--enable-local-xmms-plugin],[Install XMMS plugin to ~/.xmms/Plugins instead of system location]), + [case "${enableval}" in + yes) install_xmms_plugin_locally=true ;; + no) install_xmms_plugin_locally=false ;; +@@ -219,7 +221,7 @@ esac],[install_xmms_plugin_locally=false + AM_CONDITIONAL(FLaC__INSTALL_XMMS_PLUGIN_LOCALLY, test "x$install_xmms_plugin_locally" = xtrue) + + AC_ARG_ENABLE(xmms-plugin, +-AC_HELP_STRING([--disable-xmms-plugin], [Do not build XMMS plugin]), ++AS_HELP_STRING([--disable-xmms-plugin],[Do not build XMMS plugin]), + [case "${enableval}" in + yes) enable_xmms_plugin=true ;; + no) enable_xmms_plugin=false ;; +@@ -232,7 +234,7 @@ AM_CONDITIONAL(FLaC__HAS_XMMS, test -n " + + dnl build FLAC++ or not + AC_ARG_ENABLE([cpplibs], +-AC_HELP_STRING([--disable-cpplibs], [Do not build libFLAC++]), ++AS_HELP_STRING([--disable-cpplibs],[Do not build libFLAC++]), + [case "${enableval}" in + yes) disable_cpplibs=false ;; + no) disable_cpplibs=true ;; +@@ -242,7 +244,7 @@ AM_CONDITIONAL(FLaC__WITH_CPPLIBS, [test + + dnl check for ogg library + AC_ARG_ENABLE([ogg], +- AC_HELP_STRING([--disable-ogg], [Disable ogg support (default: test for libogg)]), ++ AS_HELP_STRING([--disable-ogg],[Disable ogg support (default: test for libogg)]), + [ want_ogg=$enableval ], [ want_ogg=yes ] ) + + if test "x$want_ogg" != "xno"; then +@@ -300,8 +302,8 @@ if test "x$debug" = xtrue; then + else + CPPFLAGS="-DNDEBUG $CPPFLAGS" + if test "x$GCC" = xyes; then +- CPPFLAGS="-DFLaC__INLINE=__inline__ $CPPFLAGS" +- CFLAGS="-O3 -funroll-loops -finline-functions -Wall -W -Winline $CFLAGS" ++ CPPFLAGS="-DFLaC__INLINE=__always_inline $CPPFLAGS" ++ CFLAGS="$CFLAGS" + fi + fi + --- Makefile.am.orig +++ Makefile.am @@ -30,7 +30,7 @@ @@ -115,3 +257,72 @@ $(CPPLIBS_DIRS) EXTRA_DIST = \ +--- include/share/alloc.h.orig ++++ include/share/alloc.h +@@ -48,10 +48,14 @@ + #define FLaC__INLINE + #endif + ++#define FLAC_ATTR_MALLOC __attribute__((__malloc__)) ++#define FLAC_ATTR_ALLOC_SIZE(n) __attribute__((alloc_size(n))) ++#define FLAC_ATTR_ALLOC_SIZE2(x,y) __attribute__((alloc_size(x,y))) ++ + /* avoid malloc()ing 0 bytes, see: + * https://www.securecoding.cert.org/confluence/display/seccode/MEM04-A.+Do+not+make+assumptions+about+the+result+of+allocating+0+bytes?focusedCommentId=5407003 + */ +-static FLaC__INLINE void *safe_malloc_(size_t size) ++static FLAC_ATTR_MALLOC FLAC_ATTR_ALLOC_SIZE(1) FLaC__INLINE void *safe_malloc_(size_t size) + { + /* malloc(0) is undefined; FLAC src convention is to always allocate */ + if(!size) +@@ -59,7 +63,7 @@ static FLaC__INLINE void *safe_malloc_(s + return malloc(size); + } + +-static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size) ++static FLAC_ATTR_MALLOC FLAC_ATTR_ALLOC_SIZE2(1,2) FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size) + { + if(!nmemb || !size) + return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */ +--- src/libFLAC/include/private/bitreader.h.orig ++++ src/libFLAC/include/private/bitreader.h +@@ -80,11 +80,11 @@ FLAC__bool FLAC__bitreader_skip_byte_blo + FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals); /* WATCHOUT: does not CRC the read data! */ + FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val); + FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter); +-FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter); ++FLAC__bool __attribute__((__hot__)) FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter); + #ifndef FLAC__NO_ASM + # ifdef FLAC__CPU_IA32 + # ifdef FLAC__HAS_NASM +-FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter); ++FLAC__bool __attribute__((__hot__)) FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter); + # endif + # endif + #endif +--- src/libFLAC/include/private/lpc.h.orig ++++ src/libFLAC/include/private/lpc.h +@@ -165,17 +165,17 @@ void FLAC__lpc_compute_residual_from_qlp + * IN data[-order,-1] previously-reconstructed historical samples + * OUT data[0,data_len-1] original signal + */ +-void FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); +-void FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); ++void __attribute__((__hot__)) FLAC__lpc_restore_signal(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); ++void __attribute__((__hot__)) FLAC__lpc_restore_signal_wide(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); + #ifndef FLAC__NO_ASM + # ifdef FLAC__CPU_IA32 + # ifdef FLAC__HAS_NASM +-void FLAC__lpc_restore_signal_asm_ia32(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); +-void FLAC__lpc_restore_signal_asm_ia32_mmx(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); ++void __attribute__((__hot__)) FLAC__lpc_restore_signal_asm_ia32(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); ++void __attribute__((__hot__)) FLAC__lpc_restore_signal_asm_ia32_mmx(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); + # endif /* FLAC__HAS_NASM */ + # elif defined FLAC__CPU_PPC +-void FLAC__lpc_restore_signal_asm_ppc_altivec_16(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); +-void FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); ++void __attribute__((__hot__)) FLAC__lpc_restore_signal_asm_ppc_altivec_16(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); ++void __attribute__((__hot__)) FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FLAC__int32 data[]); + # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */ + #endif /* FLAC__NO_ASM */ + diff --git a/flac.changes b/flac.changes index 0f38d80..98d8d8d 100644 --- a/flac.changes +++ b/flac.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Fri Jan 27 18:06:28 UTC 2012 - crrodriguez@opensuse.org + +- Fix some memory and resources leak. +- Link shared libraries with -Bsymbolic-functions +- annotate relevant functions with proper attributes to + allow the compiler generate better code (attribute hot. alloc_size) + ------------------------------------------------------------------- Tue Jan 24 16:01:40 UTC 2012 - crrodriguez@opensuse.org diff --git a/flac.spec b/flac.spec index 402c97e..387b1a2 100644 --- a/flac.spec +++ b/flac.spec @@ -51,6 +51,7 @@ Patch4: flac-1.2.1-bitreader.patch # PATCH-MISSING-TAG -- See http://wiki.opensuse.org/openSUSE:Packaging_Patches_guidelines Patch5: flac-ocloexec.patch Patch6: flac-visibility.patch +Patch7: flac-leaks.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build %description @@ -98,10 +99,11 @@ FLAC library. %patch4 %patch5 %patch6 +%patch7 %build autoreconf --force --install -%define warn_flags -W -Wall -Wstrict-prototypes -Wformat-security +%define warn_flags -O3 -W -Wall -Wstrict-prototypes -Wformat-security export CFLAGS="%{optflags} %{warn_flags}" export CXXFLAGS="$CFLAGS" %configure --disable-thorough-tests --disable-exhaustive-tests\