Commit Graph

98 Commits

Author SHA1 Message Date
Lukasz Marek
cd50a44beb lavu/mem: add av_dynarray_add_nofree function
av_dynarray_add_nofree function have similar functionality
as existing av_dynarray_add, but it doesn't deallocate memory
on fails.

Signed-off-by: Lukasz Marek <lukasz.m.luki@gmail.com>
2014-03-29 09:48:48 +01:00
Michael Niedermayer
9ba1190297 avutil/mem: avoid using intptr_t to access void* in av_dynarray_add()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-03-22 21:14:57 +01:00
Nicolas George
b0dcf76530 lavu/mem: reimplement the dynarray functions with the macro.
Signed-off-by: Nicolas George <george@nsup.org>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2014-03-22 20:53:36 +01:00
Michael Niedermayer
7c888ae746 Merge commit 'cce3e0a49f0dd030262c28d9c53de0bd2fd909c4'
* commit 'cce3e0a49f0dd030262c28d9c53de0bd2fd909c4':
  Move av_fast_{m,re}alloc from lavc to lavu.

Conflicts:
	libavcodec/avcodec.h
	libavcodec/utils.c
	libavutil/mem.c
	libavutil/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-11-14 15:04:04 +01:00
Anton Khirnov
cce3e0a49f Move av_fast_{m,re}alloc from lavc to lavu. 2013-11-14 09:42:22 +01:00
Michael Niedermayer
21b3563dcb Merge remote-tracking branch 'qatar/master'
* qatar/master:
  mem: Make av_strdup allocate using av_realloc

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-10-17 08:13:42 +02:00
Martin Storsjö
d433e1aefa mem: Make av_strdup allocate using av_realloc
This makes sure that pointers from av_strdup are reallocable,
which is used in av_dict_set if the AV_DICT_APPEND flag is set.

Nothing should rely on pointers from av_strdup being aligned.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-10-16 18:59:01 +03:00
Michael Niedermayer
6c169c2fa4 Merge commit '67e285ceca1cb602a5ab87010b30d904527924fe'
* commit '67e285ceca1cb602a5ab87010b30d904527924fe':
  mem: Handle av_reallocp(..., 0) properly

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-09-21 09:36:58 +02:00
Martin Storsjö
67e285ceca mem: Handle av_reallocp(..., 0) properly
Previously this did a double free (and returned an error).

Reported-by: Justin Ruggles
Signed-off-by: Martin Storsjö <martin@martin.st>
2013-09-20 21:23:08 +03:00
Michael Niedermayer
c74c3fb142 Merge commit '3feb3d6ce4be0a09a9f8f13d613bed25b523b6e7'
* commit '3feb3d6ce4be0a09a9f8f13d613bed25b523b6e7':
  mem: Introduce av_reallocp

Conflicts:
	doc/APIchanges
	libavutil/mem.c
	libavutil/mem.h
	libavutil/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-09-17 11:06:26 +02:00
Luca Barbato
3feb3d6ce4 mem: Introduce av_reallocp 2013-09-16 19:36:37 +02:00
Michael Niedermayer
5866c107a9 Merge commit 'c3e6e8f06c42499bd020fd0b37f9542150e6067b'
* commit 'c3e6e8f06c42499bd020fd0b37f9542150e6067b':
  mem: Do not check unsigned values for negative size

Conflicts:
	libavutil/mem.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-09-06 12:21:16 +02:00
Michael Niedermayer
92424a45d0 Merge commit 'b634b36fcebfe16b837b6c4044f5d5cb99a75040'
* commit 'b634b36fcebfe16b837b6c4044f5d5cb99a75040':
  mem: Improve documentation wording and spelling

Conflicts:
	libavutil/mem.c
	libavutil/mem.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-09-06 12:05:02 +02:00
Diego Biurrun
c3e6e8f06c mem: Do not check unsigned values for negative size 2013-09-05 12:38:43 +02:00
Diego Biurrun
b634b36fce mem: Improve documentation wording and spelling 2013-09-05 12:38:43 +02:00
Michael Niedermayer
c94f9e8542 avutil/mem: Fix flipped condition
Fixes return code and later null pointer dereference

Found-by: Laurent Butti <laurentb@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-08-09 13:47:10 +02:00
Michael Niedermayer
fbc472da29 avutil/mem: simplify av_reallocp_array() by using av_realloc_f()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-05 14:40:31 +02:00
Michael Niedermayer
30b491f1c9 Merge commit '3b4feac1ec14f861bdd7f494f288f4d8dd7f449e'
* commit '3b4feac1ec14f861bdd7f494f288f4d8dd7f449e':
  movenc: Keep track of the allocated size for the cluster array
  mem: Add av_realloc_array and av_reallocp_array

Conflicts:
	doc/APIchanges
	libavformat/movenc.c
	libavutil/mem.c
	libavutil/mem.h
	libavutil/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-05 11:19:16 +02:00
Martin Storsjö
fc962d4e7a mem: Add av_realloc_array and av_reallocp_array
These help avoiding overflows and simplify error handling.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-06-04 15:04:08 +03:00
Stefano Sabatini
e3984166a4 lavu/mem: add av_dynarray2_add()
Based on a patch by Clément Bœsch.

See thread:
From: Clément Bœsch <ubitux@gmail.com>
Subject: [FFmpeg-devel] [PATCH 1/5] lavu: add av_dynarray_alloc_elem().
Date: Sun, 14 Apr 2013 03:07:54 +0200
2013-05-13 13:52:31 +02:00
Stefano Sabatini
84be806982 lavu: define FF_MEMORY_POISON and use it
Allow single-place definition of constant used to fill poisoned memory.
2013-05-13 13:52:26 +02:00
Stefano Sabatini
ee9794ed20 lavu/mem: fix potential int overflow and crash in av_dynarray_add()
Also extend documentation accordingly.
2013-05-08 01:39:12 +02:00
Michael Niedermayer
89b5039ff2 avutil/mem: add av_memdup()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-05-02 13:44:05 +02:00
Stefano Sabatini
1c1a2d1319 lavu/mem: remove redundant comment from av_dynarray_add()
The function is documented in mem.h.
2013-04-27 20:34:10 +02:00
Fabrizio Gennari
91b747ac78 mem: Fix usage of memalign() on DJGPP.
Credits to Khusraw of bttr-software.de forum.
Signed-off-by: Carl Eugen Hoyos <cehoyos@ag.or.at>
2013-03-10 11:12:56 +01:00
Michael Niedermayer
4ba35194a9 Merge commit 'f935aca44c674d30e3ed940ef73bbad1228a5855'
* commit 'f935aca44c674d30e3ed940ef73bbad1228a5855':
  av_memcpy_backptr: avoid an infinite loop for back = 0
  4xm: check the return value of read_huffman_tables().

Conflicts:
	libavcodec/4xm.c
	libavutil/mem.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-02-24 12:22:51 +01:00
Anton Khirnov
f935aca44c av_memcpy_backptr: avoid an infinite loop for back = 0
CC:libav-stable@libav.org
2013-02-23 09:16:15 +01:00
Michael Niedermayer
2c21d34ea4 avutil/mem: do a small set of checks for memalign hack before freeing.
These can detect some kinds of memory and or pointer corruptions

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-02-22 20:42:33 +01:00
Michael Niedermayer
58f30175e1 mem: minor simplification of the alignment hack code
Idea-by: wanzhang
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2012-12-14 05:36:22 +01:00
Michael Niedermayer
99efd59626 Merge commit 'cb45553f577f8e0ebfe05d3287e1b6fa5859b967'
* commit 'cb45553f577f8e0ebfe05d3287e1b6fa5859b967':
  Remove pointless #undefs of previously forbidden functions.
  fate: Add dependencies for bmp, cdxl, dfa, mp3

Conflicts:
	doc/examples/muxing.c
	libavfilter/filtfmts.c
	libavutil/des.c
	libavutil/eval.c
	libavutil/log.c
	libavutil/parseutils.c
	tests/fate/mp3.mak

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-12-05 13:34:45 +01:00
Anton Khirnov
cb45553f57 Remove pointless #undefs of previously forbidden functions. 2012-12-04 21:40:22 +01:00
Michael Niedermayer
25ca8aef54 Merge commit '4a606c830ae664013cea33800094d4d0f4ec62da'
* commit '4a606c830ae664013cea33800094d4d0f4ec62da':
  av_memcpy_backptr: optimise some special cases
  mpegvideo: simplify dxy calculation in hpel_motion()
  build: add rules to generate preprocessed source files

Conflicts:
	Makefile
	libavutil/mem.c
	library.mak

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-11-23 13:30:51 +01:00
Mans Rullgard
4a606c830a av_memcpy_backptr: optimise some special cases
- Add special cases for offsets of 2, 3, or 4 bytes.  This means the
  offset is always >4 in the generic case, allowing 32-bit copies to
  be used there.
- Don't use memcpy() for sizes less than 16 bytes.

Signed-off-by: Mans Rullgard <mans@mansr.com>
2012-11-23 12:04:17 +00:00
Michael Niedermayer
aa604e8e33 Merge remote-tracking branch 'qatar/master'
* qatar/master:
  avutil: Make LZO decoder code configure-time selectable
  avutil: Move memcpy_backptr() to mem.c
  configure: detect parisc64 automatically
  configure: detect ppc64 automatically
  configure: detect mips64 automatically
  configure: generalise 64-bit test
  smoothstreamingenc: Don't assume streams start from timestamp 0

Conflicts:
	configure
	libavutil/Makefile
	libavutil/lzo.c
	libavutil/lzo.h
	libavutil/mem.c
	libavutil/mem.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-10-25 13:15:58 +02:00
Diego Biurrun
5bac2d0c30 avutil: Move memcpy_backptr() to mem.c
The function is used elsewhere and does not belong with the LZO code.
2012-10-25 11:36:57 +02:00
Michael Niedermayer
6912e7a008 Merge remote-tracking branch 'qatar/master'
* qatar/master:
  configure: Group math functions into a separate variable
  avutil/mem: K&R formatting cosmetics
  avutil/lzo: K&R formatting cosmetics

Conflicts:
	configure
	libavutil/mem.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-10-20 13:18:59 +02:00
Diego Biurrun
5532cf3178 avutil/mem: K&R formatting cosmetics 2012-10-20 02:34:29 +02:00
Martin Storsjö
620b1e7e98 mem: Don't abort on av_malloc(0) in debug mode
This makes the behaviour consistent between debug and release mode.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-07-10 11:37:03 +03:00
Clément Bœsch
7c84e7d337 mem: heap memory poisoning.
Enable it by default with FATE.
limitation: not random, and not supported with realloc.
2012-07-02 21:02:15 +02:00
Michael Niedermayer
cabbd271a5 Merge remote-tracking branch 'qatar/master'
* qatar/master: (24 commits)
  flvdec: remove incomplete, disabled seeking code
  mem: add support for _aligned_malloc() as found on Windows
  lavc: Extend the documentation for avcodec_init_packet
  flvdec: remove incomplete, disabled seeking code
  http: replace atoll() with strtoll()
  mpegts: remove unused/incomplete/broken seeking code
  af_amix: allow float planar sample format as input
  af_amix: use AVFloatDSPContext.vector_fmac_scalar()
  float_dsp: add x86-optimized functions for vector_fmac_scalar()
  float_dsp: Move vector_fmac_scalar() from libavcodec to libavutil
  lavr: Add x86-optimized function for flt to s32 conversion
  lavr: Add x86-optimized function for flt to s16 conversion
  lavr: Add x86-optimized functions for s32 to flt conversion
  lavr: Add x86-optimized functions for s32 to s16 conversion
  lavr: Add x86-optimized functions for s16 to flt conversion
  lavr: Add x86-optimized function for s16 to s32 conversion
  rtpenc: Support packetizing iLBC
  rtpdec: Add a depacketizer for iLBC
  Implement the iLBC storage file format
  mov: Support muxing/demuxing iLBC
  ...

Conflicts:
	Changelog
	configure
	libavcodec/avcodec.h
	libavcodec/dsputil.c
	libavcodec/version.h
	libavformat/movenc.c
	libavformat/mpegts.c
	libavformat/version.h
	libavutil/mem.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-06-19 20:53:27 +02:00
Ronald S. Bultje
be1a839ca6 mem: add support for _aligned_malloc() as found on Windows
The check uses check_func_header, since this function is
conditionally available depending on the targeted MSVCRT
version.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-06-19 10:08:00 +03:00
Reimar Döffinger
1a65d50ee7 mem.c: fix wrong comment.
Overwriting the av_malloc etc. functions is not easily
possible anymore, even for systems that support overriding
symbols in shared libraries in principle.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2012-04-16 22:13:12 +02:00
Martin Storsjö
14f063d294 mem: Consistently return NULL for av_malloc(0)
Plain POSIX malloc(0) is allowed to return either NULL or a
non-NULL pointer. The calling code should be ready to handle
a NULL return as a correct return (instead of a failure) if the size
to allocate was 0 - this makes sure the condition is handled
in a consistent way across platforms.

This also avoids calling posix_memalign(&ptr, 32, 0) on OS X,
which returns an invalid pointer (a non-NULL pointer that causes
crashes when passed to av_free).

Abort in debug mode, to help track down issues related to
incorrect handling of this case.

Signed-off-by: Martin Storsjö <martin@martin.st>
2012-04-10 11:56:42 +03:00
Michael Niedermayer
c065255bba Merge remote-tracking branch 'qatar/master'
* qatar/master:
  aacenc: Fix LONG_START windowing.
  aacenc: Fix a bug where deinterleaved samples were stored in the wrong place.
  avplay: use the correct array size for stride.
  lavc: extend doxy for avcodec_alloc_context3().
  APIchanges: mention avcodec_alloc_context()/2/3
  avcodec_align_dimensions2: set only 4 linesizes, not AV_NUM_DATA_POINTERS.
  aacsbr: ARM NEON optimised sbrdsp functions
  aacsbr: align some arrays
  aacsbr: move some simdable loops to function pointers
  cosmetics: Remove extra newlines at EOF

Conflicts:
	libavcodec/utils.c
	libavfilter/formats.c
	libavutil/mem.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-01-29 00:34:59 +01:00
Alex Converse
7181c4edee cosmetics: Remove extra newlines at EOF 2012-01-27 17:19:09 -08:00
Michael Niedermayer
5a8e994287 mem: add av_max_alloc() to limit the maximum amount that may be allocated in one piece
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2011-12-25 18:55:43 +01:00
Hanspeter Niederstrasser
bed04e2b03 Correct use of OSX to Mac OS X and properly format yasm providers on Mac OS X
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2011-12-11 03:00:30 +01:00
Michael Niedermayer
fc11927890 mem: fix memalign hack av_realloc()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2011-10-11 22:03:19 +02:00
Nicolas George
5cd754bca2 Introduce av_realloc_f.
av_realloc_f helps avoiding memory-leaks in typical uses of realloc.

Signed-off-by: Nicolas George <nicolas.george@normalesup.org>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2011-09-28 18:13:52 +02:00
Laurent Aimar
ccecab4a0d Add av_calloc() helper.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2011-09-25 00:55:25 +02:00