Commit 9a699f8d authored by Ryan C. Gordon's avatar Ryan C. Gordon

Don't leak the readahead buffer if win32 rwops file open fails.

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402464
parent 9c48629d
...@@ -59,12 +59,7 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con ...@@ -59,12 +59,7 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con
return -1; return -1;
context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* mark this as unusable */ context->hidden.win32io.h = INVALID_HANDLE_VALUE; /* mark this as unusable */
context->hidden.win32io.buffer.data = NULL;
context->hidden.win32io.buffer.data = (char *)SDL_malloc(READAHEAD_BUFFER_SIZE);
if (!context->hidden.win32io.buffer.data) {
SDL_OutOfMemory();
return -1;
}
context->hidden.win32io.buffer.size = 0; context->hidden.win32io.buffer.size = 0;
context->hidden.win32io.buffer.left = 0; context->hidden.win32io.buffer.left = 0;
...@@ -84,6 +79,12 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con ...@@ -84,6 +79,12 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con
if (!r_right && !w_right) /* inconsistent mode */ if (!r_right && !w_right) /* inconsistent mode */
return -1; /* failed (invalid call)*/ return -1; /* failed (invalid call)*/
context->hidden.win32io.buffer.data = (char *)SDL_malloc(READAHEAD_BUFFER_SIZE);
if (!context->hidden.win32io.buffer.data) {
SDL_OutOfMemory();
return -1;
}
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
{ {
size_t size = SDL_strlen(filename)+1; size_t size = SDL_strlen(filename)+1;
...@@ -92,6 +93,8 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con ...@@ -92,6 +93,8 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con
if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) { if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) {
SDL_SetError("Unable to convert filename to Unicode"); SDL_SetError("Unable to convert filename to Unicode");
SDL_stack_free(filenameW); SDL_stack_free(filenameW);
SDL_free(context->hidden.win32io.buffer.data);
context->hidden.win32io.buffer.data = NULL;
return -1; return -1;
} }
h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ,
...@@ -111,6 +114,8 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con ...@@ -111,6 +114,8 @@ static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, con
if (h==INVALID_HANDLE_VALUE) { if (h==INVALID_HANDLE_VALUE) {
SDL_SetError("Couldn't open %s",filename); SDL_SetError("Couldn't open %s",filename);
SDL_free(context->hidden.win32io.buffer.data);
context->hidden.win32io.buffer.data = NULL;
return -2; /* failed (CreateFile) */ return -2; /* failed (CreateFile) */
} }
context->hidden.win32io.h = h; context->hidden.win32io.h = h;
......
...@@ -7,7 +7,7 @@ EXE = @EXE@ ...@@ -7,7 +7,7 @@ EXE = @EXE@
CFLAGS = @CFLAGS@ CFLAGS = @CFLAGS@
LIBS = @LIBS@ LIBS = @LIBS@
TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE) testloadso$(EXE) TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testrwops$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE) testloadso$(EXE)
all: $(TARGETS) all: $(TARGETS)
...@@ -77,6 +77,9 @@ testpalette$(EXE): $(srcdir)/testpalette.c ...@@ -77,6 +77,9 @@ testpalette$(EXE): $(srcdir)/testpalette.c
testplatform$(EXE): $(srcdir)/testplatform.c testplatform$(EXE): $(srcdir)/testplatform.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS) $(CC) -o $@ $? $(CFLAGS) $(LIBS)
testrwops$(EXE): $(srcdir)/testrwops.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@
testsem$(EXE): $(srcdir)/testsem.c testsem$(EXE): $(srcdir)/testsem.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS) $(CC) -o $@ $? $(CFLAGS) $(LIBS)
......
...@@ -24,6 +24,7 @@ These are test programs for the SDL library: ...@@ -24,6 +24,7 @@ These are test programs for the SDL library:
testoverlay2 Tests the overlay flickering/scaling during playback. testoverlay2 Tests the overlay flickering/scaling during playback.
testpalette Tests palette color cycling testpalette Tests palette color cycling
testplatform Tests types, endianness and cpu capabilities testplatform Tests types, endianness and cpu capabilities
testrwops Stress-test file i/o API
testsem Tests SDL's semaphore implementation testsem Tests SDL's semaphore implementation
testsprite Example of fast sprite movement on the screen testsprite Example of fast sprite movement on the screen
testtimer Test the timer facilities testtimer Test the timer facilities
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment