- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在一个本土 C++ 框架内工作,其中一个类间接连接到 libjpeg-8c.so(作为 Ubuntu 16.04 突触包获得)。我在我的应用程序上运行 valgrind,它最终会写出图像数据,如下所示:
ImageDescriptor* pOutputImageDesc, int outputQuality)
{
//set up JPEG lib context
/* Step 4: Start compressor
* true ensures that we will write a complete interchange-JPEG file.
* Pass true unless you are very sure of what you're doing.
*/
jpeg_start_compress(&cInfo, TRUE);
/* Step 5: while (scan lines remain to be written)
* jpeg_write_scanlines(...);
* Here we use the library's state variable cInfo.next_scanline as the
* loop counter, so that we don't have to keep track ourselves.
* To keep things simple, we pass one scanline per call; you can pass
* more if you wish, though.
*/
rowStride = pInputImageDesc->width * pInputImageDesc->channels; // JSAMPLEs per row in image_buffer
while (cInfo.next_scanline < cInfo.image_height)
{
/* jpeg_write_scanlines expects an array of pointers to scanlines.
* Here the array is only one element long, but you could pass
* more than one scanline at a time if that's more convenient.
*/
rowPointerArray[0] = &inputBuffer[(cInfo.next_scanline * (rowStride))];
static_cast<void>(jpeg_write_scanlines(&cInfo, rowPointerArray, 1));
}
// Step 6: Finish compression
jpeg_finish_compress(&cInfo);
//setup external image context
// Step 7: release JPEG compression object
// This is an important step since it will release a good deal of memory.
jpeg_destroy_compress(&cInfo);
return 0;
}
与评论所说的相反,并非所有堆内存都被释放。 Valgrind 在这个 malloc() 跟踪中有不同的想法
注意:下面的跟踪是在链接到 libjpeg-8d 源之后出现的
==6025== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6025== by 0x4E4CDCE: empty_mem_output_buffer (jdatadst.c:131)
==6025== by 0x4E4373E: dump_buffer_s (jchuff.c:274)
==6025== by 0x4E4373E: emit_bits_s (jchuff.c:329)
==6025== by 0x4E4373E: encode_one_block (jchuff.c:990)
==6025== by 0x4E4373E: encode_mcu_huff (jchuff.c:1040)
==6025== by 0x4E40DAB: compress_data (jccoefct.c:208)
==6025== by 0x4E45B3F: process_data_simple_main (jcmainct.c:135)
==6025== by 0x4E3EEE3: jpeg_write_scanlines (jcapistd.c:108)
==6025== by 0x40DC4E: CompressRawToJpg(ImageDescriptor*, ImageDescriptor*, int) (ImageCaptureHelper.cpp:646)
==6025== by 0x40DFB2: WriteJpgImage(char*, ImageDescriptor*) (ImageCaptureHelper.cpp:756)
==6025== by 0x40CB18: Recognition::OutputImage::encode() (output_image.cpp:58)
==6025== by 0x403AD4: main (testImgNorm.cpp:127)
因此,在查看 mem_empty_output_buffer() 调用后,我认为此内存泄漏是由于:
1 - libjpeg-8c 写得不好(当然不清楚这个 fct 和它的调用者接口(interface),但我离题了);然而,考虑到这个库的广泛使用,我对此表示怀疑。
2 - CompressRawToJpeg() 应该在 *j_compress_ptr 中某处的 malloc 缓冲区上调用 free()
3 - 这是 libjpeg 中的一个真正的错误,我应该使用另一个库。
我希望有人遇到过类似的问题,可以为我的代码提供一种方法来写出 jpeg 图像,而不会耗尽 64K 内存块(每个文件)。
谢谢,查尔斯
最佳答案
问题很可能是 jpeg_mem_dest()
分配了自己的内存并忽略了您作为第二个参数给它的任何内容:
uint8_t* output = NULL;
unsigned long outputSize = 0;
jpeg_mem_dest(&cInfo, &output , &outputSize);
因此当 free()
在编码过程结束时未调用时会发生泄漏:
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
free(output);
关于linux - 写出 libjpeg 图像时内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62163841/
我在一个本土 C++ 框架内工作,其中一个类间接连接到 libjpeg-8c.so(作为 Ubuntu 16.04 突触包获得)。我在我的应用程序上运行 valgrind,它最终会写出图像数据,如下所
上下文 我正在运行一个 Tomcat 8.5 服务器,前端有一个 Nginx 反向代理来终止 SSL 连接,启用更多压缩。 在 Tomcat 服务器上,我有一个正在运行的 Web 应用程序,其中包含一
我正在尝试让 grunt-jsdoc-plugin 正常工作,但遇到了一个小问题。在我的控制台中,我不断收到: Running "jsdoc:dist" (jsdoc) task Warning: C
我继承了一个在数据库中存储 zip 文件的旧应用程序,需要检索该文件。在 Firefox 中运行良好,我可以打开 zip 并且其中的每个文件都很好。当我在 IE7 中运行它时,出现以下错误。 Inte
我想创建一个能够写出平面 html 文件的 cms,因此不需要数据库参与。 这个想法是CMS将允许编辑和更新文件(用php编写,如果需要的话可以使用mysql数据库),然后将这些更改保存/写出到htm
我有一个 javascript 函数,当通过 javascript 添加 td 元素时,它可以在 onclick 上正常运行。删除按钮工作正常。但是当我使用 php 创建元素并单击“删除”时,我得到:
我正在使用 node-png 库制作 png,然后将其保存在本地目录中,但是当我重新打开它时,它说它不存在。我想读入数据并将其发送出去,或者只是让响应发送一个 带图片的字段。这是我到目前为止所拥有的:
我需要一个类似于此处解释的函数... JS function for writing out a word, binary counter style ...但使用基数 7(或其他)生成(计数)从 A
我使用 matplotlib.pyplot 创建了一个简单的 hexbin 图。我没有更改任何默认设置。我的 x 轴信息范围从 2003 到 2009,而 y 值范围从 15 到 35。matplot
这是我的代码的重要部分: int realnum, positive = 0, total, poscount; for (poscount = 1; poscount > realnum;
我正在尝试在 Julia 中读取和写入一个简单的数据集。数据集是 mtcars ,取自 R,任意添加一列 bt带有随机 bool 值。文件/文件夹结构(如下)是使用 R arrow 写出的。包裹。 文
我正在尝试将数据写入包含日语字符的 Excel 文件。我正在使用 codec.open() 来获取数据,这似乎工作正常,但是当我尝试写入数据时遇到了这个错误: UnicodeEncodeError:
我是一名优秀的程序员,十分优秀!