1
jpeglib를 사용하여 jpeg를 압축하고 있습니다. 문서에서 알 수 있듯이 'mem'버퍼를 직접 풀어 줘야합니다. 하지만 jpeg_finish_compress 나 jpeg_destroy_compress 다음에 free (mem)가 오면 액세스가 잘못되었다고 추락했습니다.무료 버퍼가 jpeg_mem_dest에 의해 malloced 될 때 오류 액세스가 위반됩니다.
저와 같은 질문을 한 다른 사람이있었습니다.
실수가 있습니까? 고맙습니다!
/* Step 1: allocate and initialize JPEG compression object */
jpeg_compress_struct cinfo;
jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
cinfo.image_width = width;
cinfo.image_height = height;
unsigned char* mem = NULL;
unsigned long memSize = 0;
jpeg_mem_dest(&cinfo, &mem, &memSize);
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
/* Step 4: Start compressor */
jpeg_start_compress(&cinfo, true);
/* pointer to JSAMPLE row[s] */
JSAMPROW row_pointer[1];
/* Step 5: while (scan lines remain to be written) */
/* jpeg_write_scanlines(...); */
while (cinfo.next_scanline < cinfo.image_height) {
row_pointer[0] = &newImgData[cinfo.next_scanline * width * 3];
jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
/* Step 6: Finish compression */
jpeg_finish_compress(&cinfo);
//free(newImgData);
/* Step 7: release JPEG compression object */
/* This is an important step since it will release a good deal of memory. */
jpeg_destroy_compress(&cinfo);
free(newImgData);
나와 같은 질문을 한 다른 사람이있었습니다 .http : //stackoverflow.com/questions/32587235/how-to-release-buffer-created-by-libjpeg – zhjq