Re: [devel] [PATCH 1/1] mds: fix memleak in code and test [#1860]

2019-11-20 Thread Minh Hon Chau

Hi Thuan

ack (review only)

Thanks

Minh

On 19/11/19 5:49 pm, thuan.tran wrote:

---
  src/mds/apitest/mdstipc.h  |   2 +-
  src/mds/apitest/mdstipc_api.c  | 134 +++--
  src/mds/apitest/mdstipc_conf.c |   9 ++-
  src/mds/mds_c_sndrcv.c |   1 +
  src/mds/mds_tipc_fctrl_intf.cc |   4 +-
  5 files changed, 88 insertions(+), 62 deletions(-)

diff --git a/src/mds/apitest/mdstipc.h b/src/mds/apitest/mdstipc.h
index 5fd7b9c6e..b56940ea6 100644
--- a/src/mds/apitest/mdstipc.h
+++ b/src/mds/apitest/mdstipc.h
@@ -203,7 +203,7 @@ uint32_t destroy_pwe_on_vdest(MDS_HDL);
  
  /** USER DEFINED WRAPPERS FOR MDS SERVICE APIs **/
  
-uint32_t tet_create_task(NCS_OS_CB, NCSCONTEXT);

+uint32_t tet_create_task(NCS_OS_CB, NCSCONTEXT*);
  uint32_t tet_release_task(void *task_handle);
  int is_adest_sel_obj_found(int);
  int is_sel_obj_found(int);
diff --git a/src/mds/apitest/mdstipc_api.c b/src/mds/apitest/mdstipc_api.c
index 651365e95..847f9a7f1 100644
--- a/src/mds/apitest/mdstipc_api.c
+++ b/src/mds/apitest/mdstipc_api.c
@@ -398,7 +398,7 @@ void tet_svc_install_tp_10()
printf(
"\nTest case 10:Installing the External MIN service EXTMIN in a seperate 
thread and Uninstalling it here\n");
// Install thread
-   rc = tet_create_task((NCS_OS_CB)tet_vdest_install_thread, t_handle);
+   rc = tet_create_task((NCS_OS_CB)tet_vdest_install_thread, _handle);
if (rc != NCSCC_RC_SUCCESS) {
printf("\nFail to Install thread\n");
FAIL = 1;
@@ -999,7 +999,7 @@ void tet_svc_unstall_tp_5()
// Uninstalling the above service in a seperate thread
// Uninstall thread
rc = tet_create_task((NCS_OS_CB)tet_vdest_uninstall_thread,
-gl_tet_vdest[0].svc[0].task.t_handle);
+_tet_vdest[0].svc[0].task.t_handle);
if (rc != NCSCC_RC_SUCCESS) {
printf("\nFail to create the uninstall thread\n");
FAIL = 1;
@@ -2141,12 +2141,18 @@ void cleanup_ADEST_srv()
  {
int id;
printf("\nUninstalling all the services on this ADESt\n");
-   for (id = gl_tet_adest.svc_count - 1; id >= 0; id--)
+   for (id = gl_tet_adest.svc_count - 1; id >= 0; id--) {
+   if (mds_service_retrieve(gl_tet_adest.mds_pwe1_hdl,
+gl_tet_adest.svc[id].svc_id,
+SA_DISPATCH_ALL) != NCSCC_RC_SUCCESS) {
+   printf("Adest Svc  Retrieve Fail\n");
+   }
if (mds_service_uninstall(gl_tet_adest.mds_pwe1_hdl,
  gl_tet_adest.svc[id].svc_id) !=
NCSCC_RC_SUCCESS) {
printf("\nFail mds_service_uninstall\n");
}
+   }
  }
  
  void tet_svc_subscr_ADEST_1()

@@ -2441,7 +2447,7 @@ void tet_svc_subscr_ADEST_8()
}
printf("\nAction: Cancel in a seperate thread\n");
if (tet_create_task((NCS_OS_CB)tet_adest_cancel_thread,
-   gl_tet_adest.svc[0].task.t_handle) ==
+   _tet_adest.svc[0].task.t_handle) ==
NCSCC_RC_SUCCESS) {
printf("\nTask has been Created\n");
fflush(stdout);
@@ -2547,7 +2553,7 @@ void tet_svc_subscr_ADEST_10()
printf("\nAction: Retrieve in a seperate thread\n");
/*Retrieve thread*/
if (tet_create_task((NCS_OS_CB)tet_adest_retrieve_thread,
-   gl_tet_adest.svc[0].task.t_handle) ==
+   _tet_adest.svc[0].task.t_handle) ==
NCSCC_RC_SUCCESS) {
printf("\nTask has been Created\n");
fflush(stdout);
@@ -2751,7 +2757,10 @@ uint32_t tet_cleanup_setup()
printf("Fail mds_service_retrieve\n");
FAIL = 1;
}
-
+   if (gl_rcvdmsginfo.msg) {
+   free(gl_rcvdmsginfo.msg);
+   gl_rcvdmsginfo.msg = NULL;
+   }
if (mds_service_uninstall(
gl_tet_vdest[i].mds_pwe1_hdl,
gl_tet_vdest[i].svc[id].svc_id) !=
@@ -2785,6 +2794,10 @@ uint32_t tet_cleanup_setup()
printf("Adest Svc  Retrieve Fail\n");
FAIL = 1;
}
+   if (gl_rcvdmsginfo.msg) {
+   free(gl_rcvdmsginfo.msg);
+   gl_rcvdmsginfo.msg = NULL;
+   }
if (mds_service_uninstall(gl_tet_adest.mds_pwe1_hdl, i) !=
NCSCC_RC_SUCCESS) {
printf("Adest Svc  Uninstall 

[devel] [PATCH 1/1] mds: fix memleak in code and test [#1860]

2019-11-18 Thread thuan.tran
---
 src/mds/apitest/mdstipc.h  |   2 +-
 src/mds/apitest/mdstipc_api.c  | 134 +++--
 src/mds/apitest/mdstipc_conf.c |   9 ++-
 src/mds/mds_c_sndrcv.c |   1 +
 src/mds/mds_tipc_fctrl_intf.cc |   4 +-
 5 files changed, 88 insertions(+), 62 deletions(-)

diff --git a/src/mds/apitest/mdstipc.h b/src/mds/apitest/mdstipc.h
index 5fd7b9c6e..b56940ea6 100644
--- a/src/mds/apitest/mdstipc.h
+++ b/src/mds/apitest/mdstipc.h
@@ -203,7 +203,7 @@ uint32_t destroy_pwe_on_vdest(MDS_HDL);
 
 /** USER DEFINED WRAPPERS FOR MDS SERVICE APIs **/
 
-uint32_t tet_create_task(NCS_OS_CB, NCSCONTEXT);
+uint32_t tet_create_task(NCS_OS_CB, NCSCONTEXT*);
 uint32_t tet_release_task(void *task_handle);
 int is_adest_sel_obj_found(int);
 int is_sel_obj_found(int);
diff --git a/src/mds/apitest/mdstipc_api.c b/src/mds/apitest/mdstipc_api.c
index 651365e95..847f9a7f1 100644
--- a/src/mds/apitest/mdstipc_api.c
+++ b/src/mds/apitest/mdstipc_api.c
@@ -398,7 +398,7 @@ void tet_svc_install_tp_10()
printf(
"\nTest case 10:Installing the External MIN service EXTMIN in a 
seperate thread and Uninstalling it here\n");
// Install thread
-   rc = tet_create_task((NCS_OS_CB)tet_vdest_install_thread, t_handle);
+   rc = tet_create_task((NCS_OS_CB)tet_vdest_install_thread, _handle);
if (rc != NCSCC_RC_SUCCESS) {
printf("\nFail to Install thread\n");
FAIL = 1;
@@ -999,7 +999,7 @@ void tet_svc_unstall_tp_5()
// Uninstalling the above service in a seperate thread
// Uninstall thread
rc = tet_create_task((NCS_OS_CB)tet_vdest_uninstall_thread,
-gl_tet_vdest[0].svc[0].task.t_handle);
+_tet_vdest[0].svc[0].task.t_handle);
if (rc != NCSCC_RC_SUCCESS) {
printf("\nFail to create the uninstall thread\n");
FAIL = 1;
@@ -2141,12 +2141,18 @@ void cleanup_ADEST_srv()
 {
int id;
printf("\nUninstalling all the services on this ADESt\n");
-   for (id = gl_tet_adest.svc_count - 1; id >= 0; id--)
+   for (id = gl_tet_adest.svc_count - 1; id >= 0; id--) {
+   if (mds_service_retrieve(gl_tet_adest.mds_pwe1_hdl,
+gl_tet_adest.svc[id].svc_id,
+SA_DISPATCH_ALL) != NCSCC_RC_SUCCESS) {
+   printf("Adest Svc  Retrieve Fail\n");
+   }
if (mds_service_uninstall(gl_tet_adest.mds_pwe1_hdl,
  gl_tet_adest.svc[id].svc_id) !=
NCSCC_RC_SUCCESS) {
printf("\nFail mds_service_uninstall\n");
}
+   }
 }
 
 void tet_svc_subscr_ADEST_1()
@@ -2441,7 +2447,7 @@ void tet_svc_subscr_ADEST_8()
}
printf("\nAction: Cancel in a seperate thread\n");
if (tet_create_task((NCS_OS_CB)tet_adest_cancel_thread,
-   gl_tet_adest.svc[0].task.t_handle) ==
+   _tet_adest.svc[0].task.t_handle) ==
NCSCC_RC_SUCCESS) {
printf("\nTask has been Created\n");
fflush(stdout);
@@ -2547,7 +2553,7 @@ void tet_svc_subscr_ADEST_10()
printf("\nAction: Retrieve in a seperate thread\n");
/*Retrieve thread*/
if (tet_create_task((NCS_OS_CB)tet_adest_retrieve_thread,
-   gl_tet_adest.svc[0].task.t_handle) ==
+   _tet_adest.svc[0].task.t_handle) ==
NCSCC_RC_SUCCESS) {
printf("\nTask has been Created\n");
fflush(stdout);
@@ -2751,7 +2757,10 @@ uint32_t tet_cleanup_setup()
printf("Fail mds_service_retrieve\n");
FAIL = 1;
}
-
+   if (gl_rcvdmsginfo.msg) {
+   free(gl_rcvdmsginfo.msg);
+   gl_rcvdmsginfo.msg = NULL;
+   }
if (mds_service_uninstall(
gl_tet_vdest[i].mds_pwe1_hdl,
gl_tet_vdest[i].svc[id].svc_id) !=
@@ -2785,6 +2794,10 @@ uint32_t tet_cleanup_setup()
printf("Adest Svc  Retrieve Fail\n");
FAIL = 1;
}
+   if (gl_rcvdmsginfo.msg) {
+   free(gl_rcvdmsginfo.msg);
+   gl_rcvdmsginfo.msg = NULL;
+   }
if (mds_service_uninstall(gl_tet_adest.mds_pwe1_hdl, i) !=
NCSCC_RC_SUCCESS) {
printf("Adest Svc  Uninstall Fail\n");
@@ -2800,6 +2813,10 @@ uint32_t tet_cleanup_setup()
printf("Adest