Hedgeroid: Fixed memory handling issues
authorMedo <smaxein@googlemail.com>
Sat, 18 Aug 2012 01:20:29 +0200
changeset 7554 e50b266ed85a
parent 7552 1209e1c3c620
child 7556 4617e8ec0507
Hedgeroid: Fixed memory handling issues
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: */