From 124034579abdf8cdfe5a965307bf0027e62d1be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 13 Jun 2007 14:03:33 +0200 Subject: Backport the memmem() replacement from 1.2 series. --- configure.ac | 2 +- lib/memmem.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/os_internal.h | 9 +++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 lib/memmem.c diff --git a/configure.ac b/configure.ac index 13667417b..0d4736179 100644 --- a/configure.ac +++ b/configure.ac @@ -2113,7 +2113,7 @@ if test "x$some_snprintf" != "xyes" -o \ fi AC_FUNC_FSEEKO AC_CHECK_HEADERS(assert.h byteswap.h malloc.h execinfo.h ucontext.h sys/mman.h sys/mixer.h libgen.h netdb.h dirent.h sys/times.h sys/ioctl.h sys/param.h alloca.h) -AC_REPLACE_FUNCS(asprintf basename gettimeofday setenv strndup strpbrk strsep strtok_r timegm unsetenv) +AC_REPLACE_FUNCS(asprintf basename gettimeofday setenv strndup strpbrk strsep strtok_r timegm unsetenv memmem) AC_LIBSOURCE(hstrerror.c) AC_LINK_IFELSE([#include diff --git a/lib/memmem.c b/lib/memmem.c new file mode 100644 index 000000000..1cbe629bd --- /dev/null +++ b/lib/memmem.c @@ -0,0 +1,49 @@ +/* Copyright (C) 1991,92,93,94,96,97,98,2000,2004,2007 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include "config.h" + +#include +#include + +/* Return the first occurrence of NEEDLE in HAYSTACK. */ +void *xine_internal_memmem (const void *haystack, size_t haystack_len, + const void *needle, size_t needle_len) +{ + const char *begin; + const char *const last_possible + = (const char *) haystack + haystack_len - needle_len; + + if (needle_len == 0) + /* The first occurrence of the empty string is deemed to occur at + the beginning of the string. */ + return (void *) haystack; + + /* Sanity check, otherwise the loop might search through the whole + memory. */ + if (haystack_len < needle_len) + return NULL; + + for (begin = (const char *) haystack; begin <= last_possible; ++begin) + if (begin[0] == ((const char *) needle)[0] && + !memcmp ((const void *) &begin[1], + (const void *) ((const char *) needle + 1), + needle_len - 1)) + return (void *) begin; + + return NULL; +} diff --git a/lib/os_internal.h b/lib/os_internal.h index 5f61fb84d..f52f56847 100644 --- a/lib/os_internal.h +++ b/lib/os_internal.h @@ -268,4 +268,13 @@ void xine_private_rewinddir(DIR *); #endif +/* replacement of memmem */ +#ifndef HAVE_MEMMEM +#define HAVE_MEMMEM +#define memmem(H, HL, N, NL) \ + xine_private_memmem((H), (HL), (N), (NL)) +void *xine_internal_memmem (const void *haystack, size_t haystack_len, + const void *needle, size_t needle_len); +#endif + #endif -- cgit v1.2.3 From 72652f73d9df50711293680e9a4b2df7630e5f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 13 Jun 2007 14:54:31 +0200 Subject: Fix stupid mistake. --- lib/os_internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/os_internal.h b/lib/os_internal.h index f52f56847..11601bbdf 100644 --- a/lib/os_internal.h +++ b/lib/os_internal.h @@ -273,8 +273,8 @@ void xine_private_rewinddir(DIR *); #define HAVE_MEMMEM #define memmem(H, HL, N, NL) \ xine_private_memmem((H), (HL), (N), (NL)) -void *xine_internal_memmem (const void *haystack, size_t haystack_len, - const void *needle, size_t needle_len); +void *xine_private_memmem (const void *haystack, size_t haystack_len, + const void *needle, size_t needle_len); #endif #endif -- cgit v1.2.3 From bf51a308a15e6735a9242d85d93afb6e4574a5c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 13 Jun 2007 15:08:17 +0200 Subject: Fix leak on vorbis decoder as reported by Sander Jansen. --- src/libxineadec/xine_vorbis_decoder.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libxineadec/xine_vorbis_decoder.c b/src/libxineadec/xine_vorbis_decoder.c index ef8575949..eb0883cd9 100644 --- a/src/libxineadec/xine_vorbis_decoder.c +++ b/src/libxineadec/xine_vorbis_decoder.c @@ -79,8 +79,11 @@ static void vorbis_reset (audio_decoder_t *this_gen) { vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; - if( !this->header_count ) - vorbis_block_init(&this->vd,&this->vb); + if( this->header_count ) return; + + /* clear block first, as it might contain allocated data */ + vorbis_block_clear(&this->vb); + vorbis_block_init(&this->vd,&this->vb); } static void vorbis_discontinuity (audio_decoder_t *this_gen) { -- cgit v1.2.3