From dab5cc724da500898ddfe158c79fe128f535fa36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Fri, 8 Jan 2016 10:10:25 +0100 Subject: [PATCH] Fixes JNI crashes around LinphoneConference.getParticipants() --- coreapi/linphonecore_jni.cc | 12 ++++++------ .../common/org/linphone/core/LinphoneConference.java | 2 +- .../org/linphone/core/LinphoneConferenceImpl.java | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 650975b5f..e085315a8 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -6746,20 +6746,20 @@ JNIEXPORT jint JNICALL Java_org_linphone_core_LinphoneCoreImpl_getNortpTimeout(J -JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneConferenceImpl_getParticipants(JNIEnv *env, jobject thiz, jlong pconference) { +JNIEXPORT jobjectArray JNICALL Java_org_linphone_core_LinphoneConferenceImpl_getParticipants(JNIEnv *env, jobject thiz, jlong pconference) { MSList *participants, *it; jclass addr_class = env->FindClass("org/linphone/core/LinphoneAddressImpl"); jclass addr_list_class = env->FindClass("[Lorg/linphone/core/LinphoneAddressImpl;"); jmethodID addr_constructor = env->GetMethodID(addr_class, "", "(J)"); - jmethodID addr_list_constructor = env->GetMethodID(addr_list_class, "", "(V)"); - jmethodID addr_list_append = env->GetMethodID(addr_list_class, "add", "(Lorg/linphone/core/LinphoneAddressImpl;)Z"); - jobject jaddr_list = env->NewObject(addr_list_class, addr_list_constructor); + jobjectArray jaddr_list; + int i; participants = linphone_conference_get_participants((LinphoneConference *)pconference); - for(it = participants; it; it = ms_list_next(it)) { + jaddr_list = env->NewObjectArray(ms_list_size(participants), addr_class, NULL); + for(it=participants, i=0; it; it=ms_list_next(it), i++) { LinphoneAddress *addr = (LinphoneAddress *)it->data; jobject jaddr = env->NewObject(addr_class, addr_constructor, addr); - env->CallBooleanMethod(jaddr_list, addr_list_append, jaddr); + env->SetObjectArrayElement(jaddr_list, i, jaddr); } return jaddr_list; } diff --git a/java/common/org/linphone/core/LinphoneConference.java b/java/common/org/linphone/core/LinphoneConference.java index 9fb25d518..4b2398594 100644 --- a/java/common/org/linphone/core/LinphoneConference.java +++ b/java/common/org/linphone/core/LinphoneConference.java @@ -29,7 +29,7 @@ public interface LinphoneConference { /** * Get the URIs of all participants of the conference */ - public List getParticipants(); + public LinphoneAddress[] getParticipants(); /** * Remove a participant from the conference * @param uri The URI of the participant to remove diff --git a/java/impl/org/linphone/core/LinphoneConferenceImpl.java b/java/impl/org/linphone/core/LinphoneConferenceImpl.java index 2a3519302..c0d79e18d 100644 --- a/java/impl/org/linphone/core/LinphoneConferenceImpl.java +++ b/java/impl/org/linphone/core/LinphoneConferenceImpl.java @@ -20,7 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package org.linphone.core; import org.linphone.core.LinphoneConference; -import java.util.List; public class LinphoneConferenceImpl implements LinphoneConference { private final long nativePtr; @@ -30,8 +29,8 @@ public class LinphoneConferenceImpl implements LinphoneConference { this.nativePtr = nativePtr; } - private native List getParticipants(long nativePtr); - public List getParticipants() { + private native LinphoneAddress[] getParticipants(long nativePtr); + public LinphoneAddress[] getParticipants() { return getParticipants(nativePtr); }