mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-18 03:28:07 +00:00
Fix leak in LinphoneChatRoom refs
This commit is contained in:
parent
f2bba9df2f
commit
18ee71beab
4 changed files with 69 additions and 27 deletions
|
|
@ -506,6 +506,31 @@ jobject getChatMessage(JNIEnv *env, LinphoneChatMessage *msg){
|
|||
return jobj;
|
||||
}
|
||||
|
||||
jobject getChatRoom(JNIEnv *env, LinphoneChatRoom *room) {
|
||||
jobject jobj = 0;
|
||||
|
||||
if (room != NULL){
|
||||
LinphoneCore *lc = linphone_chat_room_get_core(room);
|
||||
LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc);
|
||||
|
||||
void *up = linphone_chat_room_get_user_data(room);
|
||||
if (up == NULL) {
|
||||
// take implicit local ref
|
||||
jobj = env->NewObject(ljb->chatRoomClass, ljb->chatRoomCtrId, (jlong)room);
|
||||
linphone_chat_room_set_user_data(room, (void*)env->NewWeakGlobalRef(jobj));
|
||||
linphone_chat_room_ref(room);
|
||||
} else {
|
||||
jobj = env->NewLocalRef((jobject)up);
|
||||
if (jobj == NULL) {
|
||||
// takes implicit local ref
|
||||
jobj=env->NewObject(ljb->chatRoomClass, ljb->chatRoomCtrId, (jlong)room);
|
||||
linphone_chat_room_set_user_data(room, (void*)env->NewWeakGlobalRef(jobj));
|
||||
}
|
||||
}
|
||||
}
|
||||
return jobj;
|
||||
}
|
||||
|
||||
jobject getFriend(JNIEnv *env, LinphoneFriend *lfriend){
|
||||
jobject jobj=0;
|
||||
|
||||
|
|
@ -911,7 +936,6 @@ public:
|
|||
}
|
||||
static void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage *msg) {
|
||||
JNIEnv *env = 0;
|
||||
jobject jmsg;
|
||||
jint result = jvm->AttachCurrentThread(&env,NULL);
|
||||
if (result != 0) {
|
||||
ms_error("cannot attach VM");
|
||||
|
|
@ -925,8 +949,8 @@ public:
|
|||
env->CallVoidMethod(lcData->listener
|
||||
,ljb->messageReceivedId
|
||||
,lcData->core
|
||||
,env->NewObject(ljb->chatRoomClass,ljb->chatRoomCtrId,(jlong)room)
|
||||
,(jmsg = getChatMessage(env, msg)));
|
||||
,getChatRoom(env, room)
|
||||
,getChatMessage(env, msg));
|
||||
handle_possible_java_exception(env, lcData->listener);
|
||||
}
|
||||
static void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room) {
|
||||
|
|
@ -943,7 +967,7 @@ public:
|
|||
env->CallVoidMethod(lcData->listener
|
||||
,ljb->isComposingReceivedId
|
||||
,lcData->core
|
||||
,env->NewObject(ljb->chatRoomClass,ljb->chatRoomCtrId,(jlong)room));
|
||||
,getChatRoom(env, room));
|
||||
handle_possible_java_exception(env, lcData->listener);
|
||||
}
|
||||
static void ecCalibrationStatus(LinphoneCore *lc, LinphoneEcCalibratorStatus status, int delay_ms, void *data) {
|
||||
|
|
@ -2133,7 +2157,7 @@ JNIEXPORT jobject JNICALL Java_org_linphone_core_LinphoneCoreImpl_getPresenceMod
|
|||
RETURN_USER_DATA_OBJECT("PresenceModelImpl", linphone_presence_model, model)
|
||||
}
|
||||
|
||||
extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getOrCreateChatRoom(JNIEnv* env
|
||||
extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getOrCreateChatRoom(JNIEnv* env
|
||||
,jobject thiz
|
||||
,jlong lc
|
||||
,jstring jto) {
|
||||
|
|
@ -2141,15 +2165,15 @@ extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getOrCreateChatRoom(JNI
|
|||
const char* to = env->GetStringUTFChars(jto, NULL);
|
||||
LinphoneChatRoom* lResult = linphone_core_get_chat_room_from_uri((LinphoneCore*)lc,to);
|
||||
env->ReleaseStringUTFChars(jto, to);
|
||||
return (jlong)lResult;
|
||||
return getChatRoom(env, lResult);
|
||||
}
|
||||
|
||||
extern "C" jlong Java_org_linphone_core_LinphoneCoreImpl_getChatRoom(JNIEnv* env
|
||||
extern "C" jobject Java_org_linphone_core_LinphoneCoreImpl_getChatRoom(JNIEnv* env
|
||||
,jobject thiz
|
||||
,jlong lc
|
||||
,jlong to) {
|
||||
LinphoneChatRoom* lResult = linphone_core_get_chat_room((LinphoneCore*)lc,(LinphoneAddress *)to);
|
||||
return (jlong)lResult;
|
||||
return getChatRoom(env, lResult);
|
||||
}
|
||||
|
||||
extern "C" void Java_org_linphone_core_LinphoneCoreImpl_enableVideo(JNIEnv* env
|
||||
|
|
@ -3998,21 +4022,25 @@ extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_unref(JNIEnv* en
|
|||
linphone_chat_message_unref((LinphoneChatMessage*)ptr);
|
||||
}
|
||||
|
||||
extern "C" jlongArray Java_org_linphone_core_LinphoneCoreImpl_getChatRooms(JNIEnv* env
|
||||
extern "C" jobjectArray Java_org_linphone_core_LinphoneCoreImpl_getChatRooms(JNIEnv* env
|
||||
,jobject thiz
|
||||
,jlong ptr) {
|
||||
const MSList* chats = linphone_core_get_chat_rooms((LinphoneCore*)ptr);
|
||||
LinphoneCore *lc = (LinphoneCore*)ptr;
|
||||
const MSList* chats = linphone_core_get_chat_rooms(lc);
|
||||
LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_core_get_user_data(lc);
|
||||
int chatsSize = ms_list_size(chats);
|
||||
jlongArray jChats = env->NewLongArray(chatsSize);
|
||||
jlong *jInternalArray = env->GetLongArrayElements(jChats, NULL);
|
||||
jobjectArray jChats = env->NewObjectArray(chatsSize, ljb->chatRoomClass, NULL);
|
||||
|
||||
for (int i = 0; i < chatsSize; i++) {
|
||||
jInternalArray[i] = (unsigned long) (chats->data);
|
||||
LinphoneChatRoom *room = (LinphoneChatRoom *)chats->data;
|
||||
jobject jroom = getChatRoom(env, room);
|
||||
if (jroom != NULL) {
|
||||
env->SetObjectArrayElement(jChats, i, jroom);
|
||||
env->DeleteLocalRef(jroom);
|
||||
}
|
||||
chats = chats->next;
|
||||
}
|
||||
|
||||
env->ReleaseLongArrayElements(jChats, jInternalArray, 0);
|
||||
|
||||
return jChats;
|
||||
}
|
||||
|
||||
|
|
@ -6852,8 +6880,8 @@ JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneCoreImpl_getVideoPreset
|
|||
return tmp ? env->NewStringUTF(tmp) : NULL;
|
||||
}
|
||||
|
||||
extern "C" jlong Java_org_linphone_core_LinphoneCallImpl_getChatRoom(JNIEnv* env ,jobject thiz, jlong ptr) {
|
||||
return (jlong) linphone_call_get_chat_room((LinphoneCall *) ptr);
|
||||
extern "C" jobject Java_org_linphone_core_LinphoneCallImpl_getChatRoom(JNIEnv* env ,jobject thiz, jlong ptr) {
|
||||
return getChatRoom(env, linphone_call_get_chat_room((LinphoneCall *) ptr));
|
||||
}
|
||||
|
||||
extern "C" void Java_org_linphone_core_LinphoneCallParamsImpl_enableRealTimeText(JNIEnv* env ,jobject thiz, jlong ptr, jboolean yesno) {
|
||||
|
|
@ -6868,6 +6896,12 @@ extern "C" void Java_org_linphone_core_LinphoneChatMessageImpl_putChar(JNIEnv* e
|
|||
linphone_chat_message_put_char((LinphoneChatMessage *)ptr, character);
|
||||
}
|
||||
|
||||
extern "C" void Java_org_linphone_core_LinphoneChatRoomImpl_finalize(JNIEnv* env, jobject thiz, jlong ptr) {
|
||||
LinphoneChatRoom *room = (LinphoneChatRoom *)ptr;
|
||||
linphone_chat_room_set_user_data(room, NULL);
|
||||
linphone_chat_room_unref(room);
|
||||
}
|
||||
|
||||
extern "C" jobject Java_org_linphone_core_LinphoneChatRoomImpl_getCall(JNIEnv* env ,jobject thiz, jlong ptr) {
|
||||
return getCall(env, linphone_chat_room_get_call((LinphoneChatRoom *)ptr));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -259,10 +259,10 @@ class LinphoneCallImpl implements LinphoneCall {
|
|||
return new LinphonePlayerImpl(getPlayer(nativePtr));
|
||||
}
|
||||
|
||||
private native long getChatRoom(long nativePtr);
|
||||
private native Object getChatRoom(long nativePtr);
|
||||
@Override
|
||||
public LinphoneChatRoom getChatRoom() {
|
||||
return new LinphoneChatRoomImpl(getChatRoom(nativePtr));
|
||||
return (LinphoneChatRoom)(getChatRoom(nativePtr));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -43,7 +43,15 @@ class LinphoneChatRoomImpl implements LinphoneChatRoom {
|
|||
String url, int state, long timestamp, boolean isRead,
|
||||
boolean isIncoming);
|
||||
private native void sendChatMessage(long ptr, Object message, long messagePtr);
|
||||
|
||||
private native void finalize(long nativePtr);
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
if (nativePtr != 0) {
|
||||
finalize(nativePtr);
|
||||
}
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
protected LinphoneChatRoomImpl(long aNativePtr) {
|
||||
nativePtr = aNativePtr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,8 +104,8 @@ class LinphoneCoreImpl implements LinphoneCore {
|
|||
private native int getPresenceInfo(long nativePtr);
|
||||
private native void setPresenceModel(long nativePtr, long presencePtr);
|
||||
private native Object getPresenceModel(long nativePtr);
|
||||
private native long getOrCreateChatRoom(long nativePtr,String to);
|
||||
private native long getChatRoom(long nativePtr,long to);
|
||||
private native Object getOrCreateChatRoom(long nativePtr,String to);
|
||||
private native Object getChatRoom(long nativePtr,long to);
|
||||
private native void enableVideo(long nativePtr,boolean vcap_enabled,boolean display_enabled);
|
||||
private native boolean isVideoEnabled(long nativePtr);
|
||||
private native boolean isVideoSupported(long nativePtr);
|
||||
|
|
@ -170,7 +170,7 @@ class LinphoneCoreImpl implements LinphoneCore {
|
|||
private native void setChatDatabasePath(long nativePtr, String path);
|
||||
private native void setCallLogsDatabasePath(long nativePtr, String path);
|
||||
private native void setFriendsDatabasePath(long nativePtr, String path);
|
||||
private native long[] getChatRooms(long nativePtr);
|
||||
private native Object[] getChatRooms(long nativePtr);
|
||||
private native int migrateToMultiTransport(long nativePtr);
|
||||
private native void migrateCallLogs(long nativePtr);
|
||||
private native void setCallErrorTone(long nativePtr, int reason, String path);
|
||||
|
|
@ -497,10 +497,10 @@ class LinphoneCoreImpl implements LinphoneCore {
|
|||
return (PresenceModel)getPresenceModel(nativePtr);
|
||||
}
|
||||
public synchronized LinphoneChatRoom getOrCreateChatRoom(String to) {
|
||||
return new LinphoneChatRoomImpl(getOrCreateChatRoom(nativePtr,to));
|
||||
return (LinphoneChatRoom)(getOrCreateChatRoom(nativePtr,to));
|
||||
}
|
||||
public synchronized LinphoneChatRoom getChatRoom(LinphoneAddress to) {
|
||||
return new LinphoneChatRoomImpl(getChatRoom(nativePtr, ((LinphoneAddressImpl) to).nativePtr));
|
||||
return (LinphoneChatRoom)(getChatRoom(nativePtr, ((LinphoneAddressImpl) to).nativePtr));
|
||||
}
|
||||
public synchronized void setPreviewWindow(Object w) {
|
||||
setPreviewWindowId(nativePtr, w);
|
||||
|
|
@ -1228,13 +1228,13 @@ class LinphoneCoreImpl implements LinphoneCore {
|
|||
}
|
||||
|
||||
public synchronized LinphoneChatRoom[] getChatRooms() {
|
||||
long[] typesPtr = getChatRooms(nativePtr);
|
||||
Object[] typesPtr = getChatRooms(nativePtr);
|
||||
if (typesPtr == null) return null;
|
||||
|
||||
LinphoneChatRoom[] proxies = new LinphoneChatRoom[typesPtr.length];
|
||||
|
||||
for (int i=0; i < proxies.length; i++) {
|
||||
proxies[i] = new LinphoneChatRoomImpl(typesPtr[i]);
|
||||
proxies[i] = (LinphoneChatRoom)(typesPtr[i]);
|
||||
}
|
||||
|
||||
return proxies;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue