Fix resource leak (Prevent)
[platform/core/connectivity/wifi-mesh-manager.git] / src / wmeshd.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include <glib.h>
25
26 #include "wmesh.h"
27 #include "wmesh-log.h"
28 #include "wmesh-util.h"
29 #include "wmesh-service.h"
30 #include "wmesh-service-interface.h"
31
32 /**< mesh service */
33 wmesh_service *meshsvc;
34
35 int main(int argc, char *argv[])
36 {
37         wmesh_service *service = NULL;
38         int ret_code = 0;
39         gboolean ret;
40
41         __WMESH_LOG_FUNC_ENTER__;
42
43 #if !GLIB_CHECK_VERSION(2, 32, 0)
44         if (!g_thread_supported())
45                 g_thread_init(NULL);
46 #endif
47
48 #if !GLIB_CHECK_VERSION(2, 36, 0)
49         g_type_init();
50 #endif
51         NOTUSED(argc);
52         NOTUSED(argv);
53
54         WMESH_LOGI("service mainloop start");
55
56         /* Create mesh service */
57         meshsvc = service = wmeshd_service_new();
58
59         /* Initialize mesh service interface layer */
60         ret = wmeshd_service_interface_init(service);
61         if (G_UNLIKELY(FALSE == ret)) {
62                 WMESH_LOGE("wmeshd_service_interface_init failed!");
63                 goto END;
64         }
65
66         /* Run mesh service */
67         ret = wmeshd_service_run(service);
68         if (G_UNLIKELY(FALSE == ret)) {
69                 WMESH_LOGE("Run service failed!");
70                 ret_code = EXIT_FAILURE;
71         }
72
73 END:
74         /* Free mesh service */
75         wmeshd_service_interface_deinit(service);
76         wmeshd_service_free(service);
77         meshsvc = NULL;
78
79         __WMESH_LOG_FUNC_EXIT__;
80         return 0;
81 }
82