Fix memory leak in wmesh_gdbus_create_network()
[platform/core/connectivity/wifi-mesh-manager.git] / src / wmesh-service.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 #include <glib.h>
20
21 #include "wmesh.h"
22 #include "wmesh-log.h"
23 #include "wmesh-util.h"
24 #include "wmesh-service.h"
25
26 wmesh_service *wmeshd_service_new()
27 {
28         wmesh_service *service;
29
30         service = g_malloc0(sizeof(struct _wmesh_service));
31
32         /* Create g-main loop */
33         service->main_loop = g_main_loop_new(NULL, FALSE);
34         if (G_UNLIKELY(NULL == service->main_loop)) {
35                 WMESH_LOGE("g-main loop creation failed!!!");
36                 g_free(service);
37                 return NULL;
38         }
39
40         return service;
41 }
42
43 void wmeshd_service_free(wmesh_service *service)
44 {
45         wmeshd_check_null_ret("service", service);
46
47         /* Unref 'g-main loop' */
48         if (service->main_loop)
49                 g_main_loop_unref(service->main_loop);
50
51         g_free(service);
52 }
53
54 gboolean wmeshd_service_run(wmesh_service *service)
55 {
56         wmeshd_check_null_ret_error("service", service, FALSE);
57         wmeshd_check_null_ret_error("service->main_loop", service->main_loop, FALSE);
58
59         g_main_loop_run(service->main_loop);
60
61         return TRUE;
62 }
63
64 gboolean wmeshd_service_exit(wmesh_service *service)
65 {
66         wmeshd_check_null_ret_error("service", service, FALSE);
67         wmeshd_check_null_ret_error("service->main_loop", service->main_loop, FALSE);
68
69         g_main_loop_quit(service->main_loop);
70
71         return TRUE;
72 }