首页 > 解决方案 > PerlXS:尝试释放可能会崩溃()

问题描述

我看到了细微的崩溃,我认为这取决于以下 XS 代码:

void
tiff_ReadRawStrip (tif, strip, size)
            TIFF            *tif
            uint32_t        strip
            tmsize_t        size
INIT:
            void            *buf;
            tmsize_t        stripsize, bufsize;
PPCODE:
            stripsize = TIFFStripSize(tif);
            buf = (unsigned char *)_TIFFmalloc(stripsize);
            bufsize = TIFFReadRawStrip(tif, strip, buf, size);
            if (bufsize > 0) {
                XPUSHs(sv_2mortal(newSVpvn(buf, bufsize)));
            }
            _TIFFfree(buf);

我想释放buf两次吗?还有其他事情吗?

背景资料

几年前,我为 libtiff 编写了 Graphics::TIFF - Perl 绑定,并已在其他各种基于 Linux 的项目中成功使用它们。最近,我在 Github 操作中让它们在 Windows 上编译。

现在一个使用 Graphics::TIFF 的项目在单元测试期间在 Windows 上看到随机崩溃,这似乎是由 Graphics::TIFF 引起的。我只能在 Github 操作中重现它们,因为我无法访问 Windows 机器。

Linux 运行程序顺利通过,因此 Windows 编译器可能对某些事情不太宽容。

标签: perlxs

解决方案


推荐阅读