[FFmpeg-devel] [PATCH] avutil/mem: remove av_realloc / av_malloc incompatibility warning

Nicolas George george at nsup.org
Tue Aug 23 18:20:14 EEST 2016


Le septidi 7 fructidor, an CCXXIV, Ronald S. Bultje a écrit :
> On Tue, Apr 21, 2015 at 9:43 AM, Nicolas George <george at nsup.org> wrote:
> > Le duodi 2 floréal, an CCXXIII, wm4 a écrit :
> > > Isn't the problem that realloc() doesn't keep the alignment?
> > No. That problem exists too
> 
> 
> That seems counter-intuitive. The problem does not exist, but it does exist
> too?
> 
> If you're saying that "the problem exists, but a user of av_realloc should
> be aware that the alignment will be lost", that's fine.

I do not remember the exact terms of the discussion. There are two issues to
be aware of:

1. Memory obtained from av_malloc() should not be used with av_realloc().

2. Memory obtained from av_realloc() is not aligned enough.

I do not remember which issue was "the" "problem" in the discussion.


Issue #1 is treacherous because it will almost always work. It comes from
POSIX, that says about realloc "If ptr does not match a pointer returned
earlier by calloc(), malloc(), or realloc() [...] the behavior is
undefined.": av_malloc() uses posix_memalign() when available, and
posix_memalign() is neither calloc(), malloc() nor realloc(), and POSIX
neglected to include a posix_realloc_memalign().

Still, with most implementations, it will work, because "it works" is an
acceptable undefined behavior; valgrind does not even report it.

I do not remember if someone found an actual libc where it did not work, or
if we had trouble with MEMALIGN_HACK between av_malloc() and av_realloc(),
or if it is purely theoretical.


Issue #2 can be relevant when ignoring issue #1; it was the cause of this:
https://trac.ffmpeg.org/ticket/1692

HtH. Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160823/0b4298d2/attachment.sig>


More information about the ffmpeg-devel mailing list