Skip to content

Commit 779c4cc

Browse files
committed
Replace g_assert with error handling
Release builds often define the compile option -DG_DISABLE_ASSERT for performance optimization. When this option is enabled, the g_assert(condition) macro is replaced by a no-op by the preprocessor. Signed-off-by: hyunil park <hyunil46.park@samsung.com>
1 parent b80c7f5 commit 779c4cc

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

c/src/ml-api-common-tizen-feature-check.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,23 @@ static feature_info_s *feature_info = NULL;
4545
/**
4646
* @brief Internal function to initialize feature state.
4747
*/
48-
static void
48+
static int
4949
ml_tizen_initialize_feature_state (void)
5050
{
5151
int i;
5252

5353
if (feature_info == NULL) {
54-
feature_info = g_new0 (feature_info_s, 1);
55-
g_assert (feature_info);
54+
feature_info = g_try_new0 (feature_info_s, 1);
55+
if (feature_info == NULL) {
56+
_ml_loge ("Failed to allocate memory for feature_info");
57+
return ML_ERROR_OUT_OF_MEMORY;
58+
}
5659

5760
g_mutex_init (&feature_info->mutex);
5861
for (i = 0; i < ML_FEATURE_MAX; i++)
5962
feature_info->feature_state[i] = NOT_CHECKED_YET;
6063
}
64+
return ML_ERROR_NONE;
6165
}
6266

6367
/**
@@ -66,7 +70,12 @@ ml_tizen_initialize_feature_state (void)
6670
int
6771
_ml_tizen_set_feature_state (ml_feature_e ml_feature, int state)
6872
{
69-
ml_tizen_initialize_feature_state ();
73+
int status;
74+
75+
status = ml_tizen_initialize_feature_state ();
76+
if (status != ML_ERROR_NONE)
77+
return status;
78+
7079
g_mutex_lock (&feature_info->mutex);
7180

7281
/**
@@ -96,8 +105,11 @@ _ml_tizen_get_feature_enabled (ml_feature_e ml_feature)
96105
{
97106
int ret;
98107
int feature_enabled;
108+
int status;
99109

100-
ml_tizen_initialize_feature_state ();
110+
status = ml_tizen_initialize_feature_state ();
111+
if (status != ML_ERROR_NONE)
112+
return status;
101113

102114
g_mutex_lock (&feature_info->mutex);
103115
feature_enabled = feature_info->feature_state[ml_feature];

0 commit comments

Comments
 (0)