forked from acouzens/open5gs
Fix the bug of segmentation fault in test program (#175)
This commit is contained in:
parent
d744893fba
commit
0992fbe7f3
|
@ -114,16 +114,11 @@ int app_did_initialize(void)
|
|||
|
||||
void app_will_terminate(void)
|
||||
{
|
||||
if (context_self()->config.db_uri)
|
||||
{
|
||||
ogs_info("DB-Client try to terminate");
|
||||
context_db_final();
|
||||
ogs_info("DB-Client terminate...done");
|
||||
}
|
||||
}
|
||||
|
||||
void app_did_terminate(void)
|
||||
{
|
||||
context_db_final();
|
||||
context_final();
|
||||
}
|
||||
|
||||
|
|
|
@ -298,7 +298,10 @@ int context_db_init(const char *db_uri)
|
|||
|
||||
const mongoc_uri_t *uri;
|
||||
|
||||
memset(&self.db, 0, sizeof self.db);
|
||||
|
||||
mongoc_init();
|
||||
self.db.initialized = true;
|
||||
|
||||
self.db.client = mongoc_client_new(db_uri);
|
||||
if (!self.db.client)
|
||||
|
@ -335,18 +338,19 @@ int context_db_init(const char *db_uri)
|
|||
|
||||
int context_db_final()
|
||||
{
|
||||
if (self.db.database)
|
||||
{
|
||||
if (self.db.database) {
|
||||
mongoc_database_destroy(self.db.database);
|
||||
self.db.database = NULL;
|
||||
}
|
||||
if (self.db.client)
|
||||
{
|
||||
if (self.db.client) {
|
||||
mongoc_client_destroy(self.db.client);
|
||||
self.db.client = NULL;
|
||||
}
|
||||
|
||||
mongoc_cleanup();
|
||||
if (self.db.initialized) {
|
||||
mongoc_cleanup();
|
||||
self.db.initialized = false;
|
||||
}
|
||||
|
||||
return OGS_OK;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ typedef struct _context_t {
|
|||
config_t config;
|
||||
|
||||
struct {
|
||||
bool initialized;
|
||||
const char *name;
|
||||
void *uri;
|
||||
void *client;
|
||||
|
|
12
src/epc.c
12
src/epc.c
|
@ -61,8 +61,7 @@ int epc_initialize(app_param_t *param)
|
|||
if (pcrf_sem1) ogs_proc_mutex_delete(pcrf_sem1);
|
||||
if (pcrf_sem2) ogs_proc_mutex_delete(pcrf_sem2);
|
||||
|
||||
app_did_terminate();
|
||||
|
||||
context_final();
|
||||
ogs_core_finalize();
|
||||
|
||||
_exit(EXIT_SUCCESS);
|
||||
|
@ -108,8 +107,7 @@ int epc_initialize(app_param_t *param)
|
|||
if (pgw_sem1) ogs_proc_mutex_delete(pgw_sem1);
|
||||
if (pgw_sem2) ogs_proc_mutex_delete(pgw_sem2);
|
||||
|
||||
app_did_terminate();
|
||||
|
||||
context_final();
|
||||
ogs_core_finalize();
|
||||
|
||||
_exit(EXIT_SUCCESS);
|
||||
|
@ -157,8 +155,7 @@ int epc_initialize(app_param_t *param)
|
|||
if (sgw_sem1) ogs_proc_mutex_delete(sgw_sem1);
|
||||
if (sgw_sem2) ogs_proc_mutex_delete(sgw_sem2);
|
||||
|
||||
app_did_terminate();
|
||||
|
||||
context_final();
|
||||
ogs_core_finalize();
|
||||
|
||||
_exit(EXIT_SUCCESS);
|
||||
|
@ -207,8 +204,7 @@ int epc_initialize(app_param_t *param)
|
|||
if (hss_sem1) ogs_proc_mutex_delete(hss_sem1);
|
||||
if (hss_sem2) ogs_proc_mutex_delete(hss_sem2);
|
||||
|
||||
app_did_terminate();
|
||||
|
||||
context_final();
|
||||
ogs_core_finalize();
|
||||
|
||||
_exit(EXIT_SUCCESS);
|
||||
|
|
|
@ -111,6 +111,7 @@ int main(int argc, const char **argv)
|
|||
|
||||
abts_init(argc, argv);
|
||||
|
||||
memset(¶m, 0, sizeof(param));
|
||||
for (i = 1; i < argc; i++) {
|
||||
/* abts_init(argc, argv) handles the following options */
|
||||
if (!strcmp(argv[i], "-v")) continue;
|
||||
|
@ -154,7 +155,6 @@ int main(int argc, const char **argv)
|
|||
ogs_core()->log.level = OGS_LOG_ERROR;
|
||||
test_initialize(¶m, argc, argv);
|
||||
|
||||
|
||||
for (i = 0; alltests[i].func; i++)
|
||||
{
|
||||
suite = alltests[i].func(suite);
|
||||
|
|
|
@ -59,7 +59,8 @@ int test_app_initialize(app_param_t *param)
|
|||
if (pcrf_sem1) ogs_proc_mutex_delete(pcrf_sem1);
|
||||
if (pcrf_sem2) ogs_proc_mutex_delete(pcrf_sem2);
|
||||
|
||||
app_did_terminate();
|
||||
context_final();
|
||||
ogs_core_finalize();
|
||||
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -104,7 +105,8 @@ int test_app_initialize(app_param_t *param)
|
|||
if (pgw_sem1) ogs_proc_mutex_delete(pgw_sem1);
|
||||
if (pgw_sem2) ogs_proc_mutex_delete(pgw_sem2);
|
||||
|
||||
app_did_terminate();
|
||||
context_final();
|
||||
ogs_core_finalize();
|
||||
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -151,7 +153,8 @@ int test_app_initialize(app_param_t *param)
|
|||
if (sgw_sem1) ogs_proc_mutex_delete(sgw_sem1);
|
||||
if (sgw_sem2) ogs_proc_mutex_delete(sgw_sem2);
|
||||
|
||||
app_did_terminate();
|
||||
context_final();
|
||||
ogs_core_finalize();
|
||||
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -199,7 +202,8 @@ int test_app_initialize(app_param_t *param)
|
|||
if (hss_sem1) ogs_proc_mutex_delete(hss_sem1);
|
||||
if (hss_sem2) ogs_proc_mutex_delete(hss_sem2);
|
||||
|
||||
app_did_terminate();
|
||||
context_final();
|
||||
ogs_core_finalize();
|
||||
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -248,7 +252,8 @@ int test_app_initialize(app_param_t *param)
|
|||
if (mme_sem1) ogs_proc_mutex_delete(mme_sem1);
|
||||
if (mme_sem2) ogs_proc_mutex_delete(mme_sem2);
|
||||
|
||||
app_did_terminate();
|
||||
context_final();
|
||||
ogs_core_finalize();
|
||||
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue