Fixed local reference leaks in messagebox implementation for Android.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 23 Nov 2014 20:38:18 +0100
changeset 9231ec22701132b5
parent 9230 7f3e7cacefd4
child 9232 6ab4ae85c41e
Fixed local reference leaks in messagebox implementation for Android.
src/core/android/SDL_android.c
     1.1 --- a/src/core/android/SDL_android.c	Sun Nov 23 20:35:51 2014 +0100
     1.2 +++ b/src/core/android/SDL_android.c	Sun Nov 23 20:38:18 2014 +0100
     1.3 @@ -1353,6 +1353,7 @@
     1.4  int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
     1.5  {
     1.6      JNIEnv *env;
     1.7 +    jclass clazz;
     1.8      jmethodID mid;
     1.9      jobject context;
    1.10      jstring title;
    1.11 @@ -1361,6 +1362,7 @@
    1.12      jintArray button_ids;
    1.13      jobjectArray button_texts;
    1.14      jintArray colors;
    1.15 +    jobject text;
    1.16      jint temp;
    1.17      int i;
    1.18  
    1.19 @@ -1368,19 +1370,23 @@
    1.20  
    1.21      /* convert parameters */
    1.22  
    1.23 +    clazz = (*env)->FindClass(env, "java/lang/String");
    1.24 +
    1.25      title = (*env)->NewStringUTF(env, messageboxdata->title);
    1.26      message = (*env)->NewStringUTF(env, messageboxdata->message);
    1.27  
    1.28      button_flags = (*env)->NewIntArray(env, messageboxdata->numbuttons);
    1.29      button_ids = (*env)->NewIntArray(env, messageboxdata->numbuttons);
    1.30      button_texts = (*env)->NewObjectArray(env, messageboxdata->numbuttons,
    1.31 -        (*env)->FindClass(env, "java/lang/String"), NULL);
    1.32 +        clazz, NULL);
    1.33      for (i = 0; i < messageboxdata->numbuttons; ++i) {
    1.34          temp = messageboxdata->buttons[i].flags;
    1.35          (*env)->SetIntArrayRegion(env, button_flags, i, 1, &temp);
    1.36          temp = messageboxdata->buttons[i].buttonid;
    1.37          (*env)->SetIntArrayRegion(env, button_ids, i, 1, &temp);
    1.38 -        (*env)->SetObjectArrayElement(env, button_texts, i, (*env)->NewStringUTF(env, messageboxdata->buttons[i].text));
    1.39 +        text = (*env)->NewStringUTF(env, messageboxdata->buttons[i].text);
    1.40 +        (*env)->SetObjectArrayElement(env, button_texts, i, text);
    1.41 +        (*env)->DeleteLocalRef(env, text);
    1.42      }
    1.43  
    1.44      if (messageboxdata->colorScheme) {
    1.45 @@ -1396,13 +1402,17 @@
    1.46          colors = NULL;
    1.47      }
    1.48  
    1.49 +    (*env)->DeleteLocalRef(env, clazz);
    1.50 +
    1.51      /* call function */
    1.52  
    1.53      mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext","()Landroid/content/Context;");
    1.54  
    1.55      context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
    1.56  
    1.57 -    mid = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, context),
    1.58 +    clazz = (*env)->GetObjectClass(env, context);
    1.59 +
    1.60 +    mid = (*env)->GetMethodID(env, clazz,
    1.61          "messageboxShowMessageBox", "(ILjava/lang/String;Ljava/lang/String;[I[I[Ljava/lang/String;[I)I");
    1.62      *buttonid = (*env)->CallIntMethod(env, context, mid,
    1.63          messageboxdata->flags,
    1.64 @@ -1413,16 +1423,15 @@
    1.65          button_texts,
    1.66          colors);
    1.67  
    1.68 +    (*env)->DeleteLocalRef(env, context);
    1.69 +    (*env)->DeleteLocalRef(env, clazz);
    1.70 +
    1.71      /* delete parameters */
    1.72  
    1.73      (*env)->DeleteLocalRef(env, title);
    1.74      (*env)->DeleteLocalRef(env, message);
    1.75      (*env)->DeleteLocalRef(env, button_flags);
    1.76      (*env)->DeleteLocalRef(env, button_ids);
    1.77 -    for (i = 0; i < messageboxdata->numbuttons; ++i) {
    1.78 -        (*env)->DeleteLocalRef(env, (*env)->GetObjectArrayElement(env, button_texts, i));
    1.79 -        (*env)->SetObjectArrayElement(env, button_texts, i, NULL);
    1.80 -    }
    1.81      (*env)->DeleteLocalRef(env, button_texts);
    1.82      (*env)->DeleteLocalRef(env, colors);
    1.83