# HG changeset patch # User Medo # Date 1345245629 -7200 # Node ID e50b266ed85a9798c879889d11898b45c12ffb44 # Parent 1209e1c3c620e4f4a033164f28f58c5ab6fc6f5f Hedgeroid: Fixed memory handling issues diff -r 1209e1c3c620 -r e50b266ed85a project_files/Android-build/SDL-android-project/jni/SDL/src/main/android/SDL_android_main.cpp --- a/project_files/Android-build/SDL-android-project/jni/SDL/src/main/android/SDL_android_main.cpp Sat Aug 18 01:12:03 2012 +0200 +++ b/project_files/Android-build/SDL-android-project/jni/SDL/src/main/android/SDL_android_main.cpp Sat Aug 18 01:20:29 2012 +0200 @@ -27,23 +27,20 @@ char *argv[argc]; jstring jstringArgv[argc]; for(int i = 0; i < argc; i++){ - jstringArgv[i] = (jstring)env->GetObjectArrayElement(strArray, i); //get the element - argv[i] = (char*)malloc(sizeof(char) * env->GetStringLength(jstringArgv[i])); - strcpy(argv[i], env->GetStringUTFChars(jstringArgv[i], JNI_FALSE)); //copy it to a mutable location - //Don't release memory the JAVA GC will take care of it - //env->ReleaseStringChars(jstringArgv[i], (jchar*)argv[i]); + jstringArgv[i] = (jstring)env->GetObjectArrayElement(strArray, i); //get the element + argv[i] = (char*)malloc(env->GetStringUTFLength(jstringArgv[i]) + 1); + const char *str = env->GetStringUTFChars(jstringArgv[i], NULL); + strcpy(argv[i], str); //copy it to a mutable location + env->ReleaseStringUTFChars(jstringArgv[i], str); } /* Run the application code! */ - int status; - status = SDL_main(argc, argv); + int status = SDL_main(argc, argv); //Clean up argv for(int i = 0; i < argc; i++){ + free(argv[i]); } - - /* We exit here for consistency with other platforms. */ - //exit(status); Xeli: Or lets not crash the entire app..... } /* vi: set ts=4 sw=4 expandtab: */