From f45c18cf6620ecfae7280c8d0fb82f928d78bd69 Mon Sep 17 00:00:00 2001 From: Martin Vajnar Date: Tue, 23 Jul 2013 16:55:00 +0200 Subject: [PATCH] JORTE: free() domain events This fixes memory leak in jORTEDomainInitEvents() and removes unused code from JOrte.java. --- .../jorte/org_ocera_orte_types_DomainEvents.h | 10 +++++- orte/java/src/org/ocera/orte/DomainApp.java | 4 ++- orte/java/src/org/ocera/orte/DomainMgr.java | 4 ++- orte/java/src/org/ocera/orte/JOrte.java | 18 ---------- .../org/ocera/orte/types/DomainEvents.java | 34 ++++++++++--------- orte/libjorte/JORTEDomainEventsDestroy.c | 20 +++++++++++ orte/libjorte/JORTEDomainInitEvents.c | 2 +- orte/libjorte/Makefile.am | 2 ++ orte/libjorte/Makefile.omk | 1 + 9 files changed, 57 insertions(+), 38 deletions(-) create mode 100644 orte/libjorte/JORTEDomainEventsDestroy.c diff --git a/orte/include/jorte/org_ocera_orte_types_DomainEvents.h b/orte/include/jorte/org_ocera_orte_types_DomainEvents.h index 3a7219c..810b833 100644 --- a/orte/include/jorte/org_ocera_orte_types_DomainEvents.h +++ b/orte/include/jorte/org_ocera_orte_types_DomainEvents.h @@ -13,7 +13,15 @@ extern "C" { * Signature: ()J */ JNIEXPORT jlong JNICALL Java_org_ocera_orte_types_DomainEvents_jORTEDomainInitEvents - (JNIEnv *, jclass); + (JNIEnv *, jobject); + +/* + * Class: org_ocera_orte_types_DomainEvents + * Method: jORTEDomainEventsDestroy + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_org_ocera_orte_types_DomainEvents_jORTEDomainEventsDestroy + (JNIEnv *, jobject, jlong); #ifdef __cplusplus } diff --git a/orte/java/src/org/ocera/orte/DomainApp.java b/orte/java/src/org/ocera/orte/DomainApp.java index eccd2af..771f5fe 100644 --- a/orte/java/src/org/ocera/orte/DomainApp.java +++ b/orte/java/src/org/ocera/orte/DomainApp.java @@ -67,7 +67,9 @@ public class DomainApp extends Domain @Override public boolean destroy() { - if(destroyAllRegTypes() && jORTEDomainAppDestroy(this.handle) && (this.props == null || this.props.destroy())) return true; + if(destroyAllRegTypes() && jORTEDomainAppDestroy(this.handle) + && (this.props == null || this.props.destroy()) + && (this.events == null || this.events.destroy())) return true; System.out.println(":j!: ORTEDomainAppDestroy() fault.."); return false; } diff --git a/orte/java/src/org/ocera/orte/DomainMgr.java b/orte/java/src/org/ocera/orte/DomainMgr.java index 13f01fa..1b6dde4 100644 --- a/orte/java/src/org/ocera/orte/DomainMgr.java +++ b/orte/java/src/org/ocera/orte/DomainMgr.java @@ -73,7 +73,9 @@ public class DomainMgr extends Domain public boolean destroy() { - if(jORTEDomainMgrDestroy(this.handle) && (this.props == null || this.props.destroy())) return true; + if(jORTEDomainMgrDestroy(this.handle) + && (this.props == null || this.props.destroy()) + && (this.events == null || this.events.destroy())) return true; System.out.println(":j!: ORTEDomainMgrDestroy() fault.."); return false; } diff --git a/orte/java/src/org/ocera/orte/JOrte.java b/orte/java/src/org/ocera/orte/JOrte.java index bfaf9cf..c3e4ae3 100644 --- a/orte/java/src/org/ocera/orte/JOrte.java +++ b/orte/java/src/org/ocera/orte/JOrte.java @@ -51,13 +51,6 @@ public class JOrte { jORTEVerbositySetLogFile(logfile); } - public static - void appSendThread(long dhandle) - { - jORTEAppSendThread(dhandle); - } - - /* ****************************************************************** * * * @@ -106,15 +99,4 @@ public class JOrte { private static native void jORTEVerbositySetLogFile(String logfile); - - /** - * jORTEVerbositySetLogFile - - * - * - * @return void - */ - private static native - void jORTEAppSendThread(long dhandle); - - } diff --git a/orte/java/src/org/ocera/orte/types/DomainEvents.java b/orte/java/src/org/ocera/orte/types/DomainEvents.java index a4295cc..801ed00 100644 --- a/orte/java/src/org/ocera/orte/types/DomainEvents.java +++ b/orte/java/src/org/ocera/orte/types/DomainEvents.java @@ -35,28 +35,30 @@ public abstract class DomainEvents { } public DomainEvents() - { - init(); - System.out.println(":j: events created & initialized.."); - } - - - /** - * Initializes DomainEvents and return their handle - * @return handle initialized DomainEvents - */ - public void init() { this.handle = jORTEDomainInitEvents(); - return; + System.out.println(":j: events created & initialized.."); } - public long getHandle() { return this.handle; } + public boolean destroy() + { + System.out.println(":j: DomainEvents destroy called.."); + + if(!jORTEDomainEventsDestroy(this.handle)) { + System.out.println(":j: DomainEvents destroy fault!"); + return false; + } + else { + System.out.println(":j: DomainEvents destroy successful.."); + return true; + } + } + public abstract void onRegFail(); public abstract void onMgrNew(AppInfo appInfo); public abstract void onMgrDelete(AppInfo appInfo); @@ -82,9 +84,9 @@ public abstract class DomainEvents { * * @return handler to default properties of a domain, NULL if error */ - private static native + private native long jORTEDomainInitEvents(); - - + private native + boolean jORTEDomainEventsDestroy(long handle); } diff --git a/orte/libjorte/JORTEDomainEventsDestroy.c b/orte/libjorte/JORTEDomainEventsDestroy.c new file mode 100644 index 0000000..b9dda00 --- /dev/null +++ b/orte/libjorte/JORTEDomainEventsDestroy.c @@ -0,0 +1,20 @@ +#include +// origin orte headers +#include "orte.h" +// pregenerated header +#include "jorte/org_ocera_orte_types_DomainEvents.h" +#include "jorte/4all.h" +#include "jorte/jorte_typedefs_defines.h" + +JNIEXPORT jboolean JNICALL +Java_org_ocera_orte_types_DomainEvents_jORTEDomainEventsDestroy +(JNIEnv *env, jobject obj, jlong handle) +{ + free((void*)handle); + + #ifdef TEST_STAGE + printf(":c: events destroyed.. \n"); + #endif + + return 1; +} diff --git a/orte/libjorte/JORTEDomainInitEvents.c b/orte/libjorte/JORTEDomainInitEvents.c index 4ec2f37..3bd004f 100644 --- a/orte/libjorte/JORTEDomainInitEvents.c +++ b/orte/libjorte/JORTEDomainInitEvents.c @@ -36,7 +36,7 @@ JNIEXPORT jlong JNICALL Java_org_ocera_orte_types_DomainEvents_jORTEDomainInitEvents -(JNIEnv *env, jclass cls) +(JNIEnv *env, jobject obj) { ORTEDomainAppEvents *evs; diff --git a/orte/libjorte/Makefile.am b/orte/libjorte/Makefile.am index cbb9c30..1e168be 100644 --- a/orte/libjorte/Makefile.am +++ b/orte/libjorte/Makefile.am @@ -13,6 +13,8 @@ JNtpTimeToStringMs.c \ JNtpTimeToStringUs.c \ JORTEDomainAppCreate.c \ JORTEDomainAppDestroy.c \ +JORTEDomainEvents.c \ +JORTEDomainEventsDestroy.c \ JORTEDomainInitEvents.c \ JORTEDomainMgrCreate.c \ JORTEDomainMgrDestroy.c \ diff --git a/orte/libjorte/Makefile.omk b/orte/libjorte/Makefile.omk index 7f1de70..ea20e48 100644 --- a/orte/libjorte/Makefile.omk +++ b/orte/libjorte/Makefile.omk @@ -30,6 +30,7 @@ JNtpTimeToStringUs.c \ JORTEDomainAppCreate.c \ JORTEDomainAppDestroy.c \ JORTEDomainEvents.c \ +JORTEDomainEventsDestroy.c \ JORTEDomainInitEvents.c \ JORTEDomainMgrCreate.c \ JORTEDomainMgrDestroy.c \ -- 2.39.2