Set the error after freeing stuff, just in case one of those functions resets SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Tue, 10 Jul 2007 19:03:44 +0000
branchSDL-1.2
changeset 4040 8515468091e3
parent 4039 7fd9a811efc7
child 4041 1c291c47cf1e
Set the error after freeing stuff, just in case one of those functions resets the error string.
src/file/SDL_rwops.c
--- a/src/file/SDL_rwops.c	Tue Jul 10 18:56:08 2007 +0000
+++ b/src/file/SDL_rwops.c	Tue Jul 10 19:03:44 2007 +0000
@@ -91,10 +91,10 @@
 		wchar_t *filenameW = SDL_stack_alloc(wchar_t, size);
 
 		if ( MultiByteToWideChar(CP_UTF8, 0, filename, -1, filenameW, size) == 0 ) {
-			SDL_SetError("Unable to convert filename to Unicode");
 			SDL_stack_free(filenameW);
 			SDL_free(context->hidden.win32io.buffer.data);
 			context->hidden.win32io.buffer.data = NULL;
+			SDL_SetError("Unable to convert filename to Unicode");
 			return -1;
 		}
 		h = CreateFile(filenameW, (w_right|r_right), (w_right)? 0 : FILE_SHARE_READ, 
@@ -113,9 +113,9 @@
 #endif /* _WIN32_WCE */
 
 	if (h==INVALID_HANDLE_VALUE) {
-		SDL_SetError("Couldn't open %s",filename);
 		SDL_free(context->hidden.win32io.buffer.data);
 		context->hidden.win32io.buffer.data = NULL;
+		SDL_SetError("Couldn't open %s",filename);
 		return -2; /* failed (CreateFile) */
 	}
 	context->hidden.win32io.h = h;