[FFmpeg-devel] [PATCH] av_malloc() workaround for QNX platform

Mike Gorchak mike.gorchak.qnx at gmail.com
Thu Feb 7 15:31:01 CET 2013


Hi,

I've attached a patch for QNX which resolves issues of memalign() and
posix_memalign() functions. I know this looks like a dirty hack, but this
is the only way to workaround current issues.

By the way I have found a bug in the av_malloc() function when
CONFIG_MEMALIGN_HACK is used. I've tried it instead on QNX
instead of posix_memalign()/memaligh() functions. The code looks like:

#if CONFIG_MEMALIGN_HACK
    ptr = malloc(size + ALIGN);
    if (!ptr)
        return ptr;
    diff              = ((~(long)ptr)&(ALIGN - 1)) + 1;
    ptr               = (char *)ptr + diff;
    ((char *)ptr)[-1] = diff;

After malloc() there is needed a check for ptr which can be ALREADY
aligned. In this case we have not to execute this line: ((char
*)ptr)[-1] = diff; which can cause a memory trashing. But better to
allocate (size+2*ALIGN) bytes and then move ptr forward for at least ALIGN
bytes to make sure that buffer has spare space for writting a 'diff'
value.

Thanks in advance!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mplayer-qnx-ffmpeg-mem.diff
Type: application/octet-stream
Size: 977 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130207/2def68a5/attachment.obj>


More information about the ffmpeg-devel mailing list