Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Changed JpegIo thumbnail creation to use malloc/free for dest buffer #1046

Merged
merged 1 commit into from

3 participants

arnova Cory Fields Jools Wills
Deleted user

Changed JpegIo thumbnail creation to use malloc/free rather than new/delete, as libjpeg will use realloc to increase the buffer as needed. Mixing them like this could have undefined effects or cause memory leaks. This code on the xbox1 version of xbmc did indeed leak.

Jools Wills joolswills Changed JpegIo thumbnail creation to use malloc/free rather than new/…
…delete, as

libjpeg will use  realloc to increase the buffer as needed. Mixing them like this could have undefined effects or cause memory leaks.
This code on the xbox1 version of xbmc did indeed leak.
55711b0
Cory Fields theuni was assigned
Cory Fields theuni merged commit 5c9cea7 into from
arnova
Collaborator

Nice catch :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 4, 2012
  1. Jools Wills

    Changed JpegIo thumbnail creation to use malloc/free rather than new/…

    joolswills authored
    …delete, as
    
    libjpeg will use  realloc to increase the buffer as needed. Mixing them like this could have undefined effects or cause memory leaks.
    This code on the xbox1 version of xbmc did indeed leak.
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 4 deletions.
  1. +11 −4 xbmc/guilib/JpegIO.cpp
15 xbmc/guilib/JpegIO.cpp
View
@@ -436,7 +436,7 @@ bool CJpegIO::CreateThumbnailFromSurface(unsigned char* buffer, unsigned int wid
struct my_error_mgr jerr;
JSAMPROW row_pointer[1];
long unsigned int outBufSize = 0;
- unsigned char* result = new unsigned char [(width * height)]; //Initial buffer. Grows as-needed.
+ unsigned char* result;
unsigned char* src = buffer;
unsigned char* rgbbuf, *src2, *dst2;
@@ -446,6 +446,13 @@ bool CJpegIO::CreateThumbnailFromSurface(unsigned char* buffer, unsigned int wid
return false;
}
+ result = (unsigned char*) malloc(width * height); //Initial buffer. Grows as-needed.
+ if (result == NULL)
+ {
+ CLog::Log(LOGERROR, "JpegIO::CreateThumbnailFromSurface error allocating memory for image buffer");
+ return false;
+ }
+
if(format == XB_FMT_RGB8)
{
rgbbuf = buffer;
@@ -482,7 +489,7 @@ bool CJpegIO::CreateThumbnailFromSurface(unsigned char* buffer, unsigned int wid
if (setjmp(jerr.setjmp_buffer))
{
jpeg_destroy_compress(&cinfo);
- delete [] result;
+ free(result);
if(format != XB_FMT_RGB8)
delete [] rgbbuf;
return false;
@@ -519,10 +526,10 @@ bool CJpegIO::CreateThumbnailFromSurface(unsigned char* buffer, unsigned int wid
{
file.Write(result, outBufSize);
file.Close();
- delete [] result;
+ free(result);
return true;
}
- delete [] result;
+ free(result);
return false;
}
Something went wrong with that request. Please try again.