[libmm-camcorder] g_free and g_printf function fixes 34/58034/1
authorHyuntae, Kim <ht1211.kim@samsung.com>
Wed, 27 Jan 2016 04:15:11 +0000 (13:15 +0900)
committerHyuntae, Kim <ht1211.kim@samsung.com>
Wed, 27 Jan 2016 04:16:13 +0000 (13:16 +0900)
Change-Id: Ibf1167c47fc58178bbe2c71b8f11cda2e5cefb43

12 files changed:
packaging/libmm-camcorder.spec
src/include/mm_camcorder_configure.h
src/mm_camcorder_attribute.c
src/mm_camcorder_audiorec.c
src/mm_camcorder_client.c
src/mm_camcorder_configure.c
src/mm_camcorder_gstcommon.c
src/mm_camcorder_internal.c
src/mm_camcorder_stillshot.c
src/mm_camcorder_util.c
src/mm_camcorder_videorec.c
test/mm_camcorder_testsuite.c

index 1172658..760c77e 100644 (file)
@@ -2,7 +2,7 @@
 
 Name:       libmm-camcorder
 Summary:    Camera and recorder library
-Version:    0.10.32
+Version:    0.10.33
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index afb0581..0d483ba 100644 (file)
@@ -31,6 +31,12 @@ extern "C" {
 ========================================================================================*/
 #define SAFE_FREE(x) \
        if (x) {\
+               free(x); \
+               x = NULL; \
+       }
+
+#define SAFE_G_FREE(x) \
+       if (x) {\
                g_free(x); \
                x = NULL; \
        }
index a5a88e4..409aba4 100644 (file)
@@ -2955,11 +2955,8 @@ bool _mmcamcorder_commit_target_filename(MMHandleType handle, int attr_idx, cons
        }
 
        if (sc->info_video) {
-               if (sc->info_video->filename) {
-                       free(sc->info_video->filename);
-                       sc->info_video->filename = NULL;
-               }
-               sc->info_video->filename = strdup(filename);
+               SAFE_G_FREE(sc->info_video->filename);
+               sc->info_video->filename = g_strdup(filename);
                if (sc->info_video->filename == NULL) {
                        _mmcam_dbg_err("failed to strdup filename [%s]", filename);
                        return FALSE;
index 8362140..4cfbb72 100644 (file)
@@ -408,7 +408,7 @@ _mmcamcorder_audio_command(MMHandleType handle, int command)
                                goto _ERR_CAMCORDER_AUDIO_COMMAND;
                        }
 
-                       info->filename = strdup(temp_filename);
+                       info->filename = g_strdup(temp_filename);
                        if (!info->filename) {
                                _mmcam_dbg_err("STRDUP was failed");
                                goto _ERR_CAMCORDER_AUDIO_COMMAND;
@@ -541,8 +541,7 @@ _mmcamcorder_audio_command(MMHandleType handle, int command)
                if (info->filename) {
                        _mmcam_dbg_log("file delete(%s)", info->filename);
                        unlink(info->filename);
-                       g_free(info->filename);
-                       info->filename = NULL;
+                       SAFE_G_FREE(info->filename);
                }
                break;
 
@@ -655,7 +654,7 @@ int _mmcamcorder_audio_handle_eos(MMHandleType handle)
 
        /* Send recording report message to application */
        msg.id = MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED;
-       report = (MMCamRecordingReport*) malloc(sizeof(MMCamRecordingReport));
+       report = (MMCamRecordingReport*) g_malloc(sizeof(MMCamRecordingReport));
        if (!report) {
                _mmcam_dbg_err("Recording report fail(%s). Out of memory.", info->filename);
                return FALSE;
@@ -668,7 +667,7 @@ int _mmcamcorder_audio_handle_eos(MMHandleType handle)
        }
 /* END TAG HERE */
 
-       report->recording_filename = strdup(info->filename);
+       report->recording_filename = g_strdup(info->filename);
        msg.param.data= report;
 
        _mmcamcorder_send_message(handle, &msg);
@@ -686,8 +685,7 @@ int _mmcamcorder_audio_handle_eos(MMHandleType handle)
        sc->isMaxsizePausing = FALSE;
        sc->isMaxtimePausing = FALSE;
 
-       g_free(info->filename);
-       info->filename = NULL;
+       SAFE_G_FREE(info->filename);
 
        _mmcam_dbg_err("_MMCamcorder_CMD_COMMIT : end");
 
index 4439d60..7873b6d 100644 (file)
@@ -619,8 +619,7 @@ int _mmcamcorder_client_videosink_window_set(MMHandleType handle, type_element*
        if (err != MM_ERROR_NONE) {
                if (err_name) {
                        _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
-                       free(err_name);
-                       err_name = NULL;
+                       SAFE_FREE(err_name);
                } else {
                        _mmcam_dbg_err("failed to get attributes [0x%x]", err);
                }
index 9a4c705..b6e4a3a 100644 (file)
@@ -46,7 +46,7 @@
 
 char *get_new_string(char* src_string)
 {
-       return strdup(src_string);
+       return g_strdup(src_string);
 }
 
 void _mmcamcorder_conf_init(MMHandleType handle, int type, camera_conf** configure_info)
@@ -983,7 +983,7 @@ int _mmcamcorder_conf_parse_info(MMHandleType handle, int type, FILE* fd, camera
        if (buffer_string == NULL) {
                _mmcam_dbg_err("buffer_string alloc failed : %d", sizeof(char) * BUFFER_LENGTH_STRING);
                *configure_info = NULL;
-               g_free(new_conf);
+               SAFE_G_FREE(new_conf);
                return MM_ERROR_CAMCORDER_LOW_MEMORY;
        }
 
@@ -995,8 +995,8 @@ int _mmcamcorder_conf_parse_info(MMHandleType handle, int type, FILE* fd, camera
        if (fd == NULL) {
                _mmcam_dbg_err("failed file descriptor fail");
                *configure_info = NULL;
-               g_free(buffer_string);
-               g_free(new_conf);
+               SAFE_G_FREE(buffer_string);
+               SAFE_G_FREE(new_conf);
                return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
        }
 
@@ -1068,7 +1068,7 @@ int _mmcamcorder_conf_parse_info(MMHandleType handle, int type, FILE* fd, camera
                                        {
                                                read_main = 1;
                                                buffer_token[0] = token;
-                                               SAFE_FREE( detail_string );
+                                               SAFE_G_FREE( detail_string );
                                                break;
                                        }
 
@@ -1076,7 +1076,7 @@ int _mmcamcorder_conf_parse_info(MMHandleType handle, int type, FILE* fd, camera
                                }
                                else
                                {
-                                       SAFE_FREE( detail_string );
+                                       SAFE_G_FREE( detail_string );
                                }
                        }
 
@@ -1085,7 +1085,7 @@ int _mmcamcorder_conf_parse_info(MMHandleType handle, int type, FILE* fd, camera
                        if( count_details == 0 )
                        {
                                _mmcam_dbg_warn( "category %s has no detail value... skip this category...", category_name );
-                               SAFE_FREE(category_name);
+                               SAFE_G_FREE(category_name);
                                continue;
                        }
 
@@ -1179,17 +1179,17 @@ int _mmcamcorder_conf_parse_info(MMHandleType handle, int type, FILE* fd, camera
 
                                for( i = 0 ; i < count_details ; i++ )
                                {
-                                       SAFE_FREE( buffer_details[i] );
+                                       SAFE_G_FREE( buffer_details[i] );
                                }
                        }
                }
 
-               SAFE_FREE(category_name);
+               SAFE_G_FREE(category_name);
        }
 
        //(*configure_info) = new_conf;
 
-       SAFE_FREE( buffer_string );
+       SAFE_G_FREE( buffer_string );
 
        /*_mmcam_dbg_log( "Done." );*/
 
@@ -1236,63 +1236,62 @@ void _mmcamcorder_conf_release_info(MMHandleType handle, camera_conf **configure
                                        switch (type) {
                                        case CONFIGURE_VALUE_INT:
                                                temp_int = (type_int2*)(temp_conf->info[i]->detail_info[j]);
-                                               SAFE_FREE(temp_int->name);
+                                               SAFE_G_FREE(temp_int->name);
                                                break;
                                        case CONFIGURE_VALUE_INT_RANGE:
                                                temp_int_range = (type_int_range*)(temp_conf->info[i]->detail_info[j]);
-                                               SAFE_FREE(temp_int_range->name);
+                                               SAFE_G_FREE(temp_int_range->name);
                                                break;
                                        case CONFIGURE_VALUE_INT_ARRAY:
                                                temp_int_array = (type_int_array*)(temp_conf->info[i]->detail_info[j]);
-                                               SAFE_FREE(temp_int_array->name);
-                                               SAFE_FREE(temp_int_array->value);
+                                               SAFE_G_FREE(temp_int_array->name);
+                                               SAFE_G_FREE(temp_int_array->value);
                                                break;
                                        case CONFIGURE_VALUE_INT_PAIR_ARRAY:
                                                temp_int_pair_array = (type_int_pair_array*)(temp_conf->info[i]->detail_info[j]);
-                                               SAFE_FREE(temp_int_pair_array->name);
-                                               SAFE_FREE(temp_int_pair_array->value[0]);
-                                               SAFE_FREE(temp_int_pair_array->value[1]);
+                                               SAFE_G_FREE(temp_int_pair_array->name);
+                                               SAFE_G_FREE(temp_int_pair_array->value[0]);
+                                               SAFE_G_FREE(temp_int_pair_array->value[1]);
                                                break;
                                        case CONFIGURE_VALUE_STRING:
                                                temp_string = (type_string2*)(temp_conf->info[i]->detail_info[j]);
-                                               SAFE_FREE(temp_string->name);
-                                               SAFE_FREE(temp_string->value);
+                                               SAFE_G_FREE(temp_string->name);
+                                               SAFE_G_FREE(temp_string->value);
                                                break;
                                        case CONFIGURE_VALUE_STRING_ARRAY:
                                                temp_string_array = (type_string_array*)(temp_conf->info[i]->detail_info[j]);
-                                               SAFE_FREE(temp_string_array->name);
+                                               SAFE_G_FREE(temp_string_array->name);
                                                if (temp_string_array->value) {
                                                        count = temp_string_array->count;
                                                        for (k = 0 ; k < count ; k++) {
-                                                               SAFE_FREE(temp_string_array->value[k]);
+                                                               SAFE_G_FREE(temp_string_array->value[k]);
                                                        }
-                                                       g_free(temp_string_array->value);
-                                                       temp_string_array->value = NULL;
+                                                       SAFE_G_FREE(temp_string_array->value);
                                                }
-                                               SAFE_FREE(temp_string_array->default_value);
+                                               SAFE_G_FREE(temp_string_array->default_value);
                                                break;
                                        case CONFIGURE_VALUE_ELEMENT:
                                                temp_element = (type_element2*)(temp_conf->info[i]->detail_info[j]);
-                                               SAFE_FREE(temp_element->name);
-                                               SAFE_FREE(temp_element->element_name);
+                                               SAFE_G_FREE(temp_element->name);
+                                               SAFE_G_FREE(temp_element->element_name);
 
                                                if (temp_element->value_int) {
                                                        count = temp_element->count_int;
                                                        for (k = 0 ; k < count ; k++) {
-                                                               SAFE_FREE(temp_element->value_int[k]->name);
-                                                               SAFE_FREE(temp_element->value_int[k]);
+                                                               SAFE_G_FREE(temp_element->value_int[k]->name);
+                                                               SAFE_G_FREE(temp_element->value_int[k]);
                                                        }
-                                                       g_free(temp_element->value_int);
+                                                       SAFE_G_FREE(temp_element->value_int);
                                                }
 
                                                if (temp_element->value_string) {
                                                        count = temp_element->count_string;
                                                        for (k = 0 ; k < count ; k++) {
-                                                               SAFE_FREE(temp_element->value_string[k]->name);
-                                                               SAFE_FREE(temp_element->value_string[k]->value);
-                                                               SAFE_FREE(temp_element->value_string[k]);
+                                                               SAFE_G_FREE(temp_element->value_string[k]->name);
+                                                               SAFE_G_FREE(temp_element->value_string[k]->value);
+                                                               SAFE_G_FREE(temp_element->value_string[k]);
                                                        }
-                                                       g_free(temp_element->value_string);
+                                                       SAFE_G_FREE(temp_element->value_string);
                                                }
                                                break;
                                        default:
@@ -1301,20 +1300,18 @@ void _mmcamcorder_conf_release_info(MMHandleType handle, camera_conf **configure
                                        }
                                }
 
-                               SAFE_FREE(temp_conf->info[i]->detail_info[j]);
-                               temp_conf->info[i]->detail_info[j] = NULL;
+                               SAFE_G_FREE(temp_conf->info[i]->detail_info[j]);
                        }
 
-                       SAFE_FREE(temp_conf->info[i]->detail_info);
-                       temp_conf->info[i]->detail_info = NULL;
+                       SAFE_G_FREE(temp_conf->info[i]->detail_info);
 
-                       SAFE_FREE(temp_conf->info[i]);
+                       SAFE_G_FREE(temp_conf->info[i]);
                        temp_conf->info[i] = NULL;
                }
        }
 
-       SAFE_FREE((*configure_info)->info);
-       SAFE_FREE((*configure_info));
+       SAFE_G_FREE((*configure_info)->info);
+       SAFE_G_FREE((*configure_info));
 
        _mmcam_dbg_log("Done.");
 }
@@ -1514,12 +1511,8 @@ int _mmcamcorder_conf_add_info(MMHandleType handle, int type, conf_detail** info
                                new_int_array->name = get_new_string( buffer_token[0] );
                                new_int_array->value = (int*)g_malloc0( sizeof(int)*count_value );
                                if (new_int_array->value == NULL) {
-                                       if (new_int_array->name) {
-                                               free(new_int_array->name);
-                                               new_int_array->name = NULL;
-                                       }
-                                       free(new_int_array);
-                                       new_int_array = NULL;
+                                       SAFE_G_FREE(new_int_array->name);
+                                       SAFE_G_FREE(new_int_array);
                                        _mmcam_dbg_err("allocation failed");
                                        break;
                                }
@@ -1548,27 +1541,18 @@ int _mmcamcorder_conf_add_info(MMHandleType handle, int type, conf_detail** info
                                        break;
                                }
                                new_int_pair_array->name     = get_new_string( buffer_token[0] );
-                               new_int_pair_array->value[0] = (int*)g_malloc( sizeof(int)*(count_value) );
+                               new_int_pair_array->value[0] = (int*)g_malloc0( sizeof(int)*(count_value) );
                                if ( new_int_pair_array->value[0] == NULL ) {
-                                       if (new_int_pair_array->name) {
-                                               free( new_int_pair_array->name );
-                                               new_int_pair_array->name = NULL;
-                                       }
-                                       g_free( new_int_pair_array );
-                                       new_int_pair_array = NULL;
+                                       SAFE_G_FREE(new_int_pair_array->name);
+                                       SAFE_G_FREE(new_int_pair_array);
                                        _mmcam_dbg_err("allocation failed");
                                        break;
                                }
-                               new_int_pair_array->value[1] = (int*)g_malloc( sizeof(int)*(count_value) );
+                               new_int_pair_array->value[1] = (int*)g_malloc0( sizeof(int)*(count_value) );
                                if ( new_int_pair_array->value[1] == NULL ) {
-                                       g_free( new_int_pair_array->value[0] );
-                                       new_int_pair_array->value[0] = NULL;
-                                       if (new_int_pair_array->name) {
-                                               free( new_int_pair_array->name );
-                                               new_int_pair_array->name = NULL;
-                                       }
-                                       g_free( new_int_pair_array );
-                                       new_int_pair_array = NULL;
+                                       SAFE_G_FREE(new_int_pair_array->value[0]);
+                                       SAFE_G_FREE(new_int_pair_array->name);
+                                       SAFE_G_FREE(new_int_pair_array);
                                        _mmcam_dbg_err("allocation failed");
                                        break;
                                }
@@ -1624,12 +1608,8 @@ int _mmcamcorder_conf_add_info(MMHandleType handle, int type, conf_detail** info
                                new_string_array->count = count_value;
                                new_string_array->value = (char**)g_malloc0( sizeof(char*)*count_value );
                                if ( new_string_array->value == NULL ) {
-                                       if (new_string_array->name) {
-                                               free(new_string_array->name);
-                                               new_string_array->name = NULL;
-                                       }
-                                       free(new_string_array);
-                                       new_string_array = NULL;
+                                       SAFE_G_FREE(new_string_array->name);
+                                       SAFE_G_FREE(new_string_array);
                                        _mmcam_dbg_err("allocation failed");
                                        break;
                                }
@@ -1669,7 +1649,7 @@ int _mmcamcorder_conf_add_info(MMHandleType handle, int type, conf_detail** info
                                        new_element->value_int = (type_int2**)g_malloc0( sizeof(type_int2*)*(new_element->count_int) );
                                        if ( new_element->value_int) {
                                                for ( j = 0 ; j < new_element->count_int ; j++ ) {
-                                                       new_element->value_int[j]        = (type_int2*)g_malloc( sizeof(type_int2) );
+                                                       new_element->value_int[j]        = (type_int2*)g_malloc0( sizeof(type_int2) );
                                                        if ( new_element->value_int[j] ) {
                                                                new_element->value_int[j]->name  = get_new_string( buffer_token[4+(j<<1)] );
                                                                new_element->value_int[j]->value = atoi( buffer_token[5+(j<<1)] );
index 0586cbc..5fabb05 100644 (file)
@@ -694,7 +694,7 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
 
                        caps_str = gst_caps_to_string(video_caps);
                        _mmcam_dbg_log("encodebin caps [%s]", caps_str);
-                       free(caps_str);
+                       g_free(caps_str);
                        caps_str = NULL;
 
                        MMCAMCORDER_G_OBJECT_SET_POINTER(sc->encode_element[_MMCAMCORDER_ENCSINK_FILT].gst, "caps", video_caps);
@@ -717,13 +717,24 @@ int _mmcamcorder_create_encodesink_bin(MMHandleType handle, MMCamcorderEncodebin
        _MMCAMCORDER_ELEMENT_MAKE(sc, sc->encode_element, _MMCAMCORDER_ENCSINK_ENCBIN, "encodebin", "encodesink_encbin", element_list, err);
 
        /* check element availability */
-       mm_camcorder_get_attributes(handle, &err_name,
+       err = mm_camcorder_get_attributes(handle, &err_name,
                                    MMCAM_AUDIO_ENCODER, &audio_enc,
                                    MMCAM_AUDIO_CHANNEL, &channel,
                                    MMCAM_VIDEO_ENCODER_BITRATE, &v_bitrate,
                                    MMCAM_AUDIO_ENCODER_BITRATE, &a_bitrate,
                                    NULL);
 
+       if (err != MM_ERROR_NONE) {
+               if (err_name) {
+                       _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
+                       SAFE_FREE(err_name);
+               } else {
+                       _mmcam_dbg_err("failed to get attributes [0x%x]", err);
+               }
+
+               return err;
+       }
+
        _mmcam_dbg_log("Profile[%d]", profile);
 
        /* Set information */
@@ -1219,8 +1230,7 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
        if (err != MM_ERROR_NONE) {
                if (err_name) {
                        _mmcam_dbg_err("failed to get attributes [%s][0x%x]", err_name, err);
-                       free(err_name);
-                       err_name = NULL;
+                       SAFE_FREE(err_name);
                } else {
                        _mmcam_dbg_err("failed to get attributes [0x%x]", err);
                }
@@ -1353,7 +1363,7 @@ gboolean _mmcamcorder_get_device_info(MMHandleType handle)
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
        _MMCamcorderSubContext *sc = NULL;
        GstCameraControl *control = NULL;
-       GstCameraControlExifInfo exif_info;
+       GstCameraControlExifInfo exif_info = {0,};
 
        mmf_return_val_if_fail(hcamcorder, FALSE);
        sc = MMF_CAMCORDER_SUBCONTEXT(handle);
@@ -1371,7 +1381,8 @@ gboolean _mmcamcorder_get_device_info(MMHandleType handle)
                        control = GST_CAMERA_CONTROL(sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
                        if (control != NULL) {
                                gst_camera_control_get_exif_info(control, &exif_info); //get video input device information
-                               focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
+                               if (exif_info.focal_len_denominator != 0)
+                                       focal_len = ((double)exif_info.focal_len_numerator) / ((double) exif_info.focal_len_denominator);
                        } else {
                                _mmcam_dbg_err("Fail to get camera control interface!");
                                focal_len = 0.0;
@@ -1384,10 +1395,7 @@ gboolean _mmcamcorder_get_device_info(MMHandleType handle)
                                                  NULL);
                if (err != MM_ERROR_NONE) {
                        _mmcam_dbg_err("Set attributes error(%s:%x)!", err_name, err);
-                       if (err_name) {
-                               free(err_name);
-                               err_name = NULL;
-                       }
+                       SAFE_FREE(err_name);
                        return FALSE;
                }
        } else {
@@ -1760,7 +1768,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_push_buffer_to_record(Gst
                                char *caps_string = gst_caps_to_string(caps);
                                if (caps_string) {
                                        _mmcam_dbg_log("%s", caps_string);
-                                       free(caps_string);
+                                       g_free(caps_string);
                                        caps_string = NULL;
                                }
                                gst_caps_unref(caps);
@@ -2291,11 +2299,14 @@ bool _mmcamcorder_set_videosrc_caps(MMHandleType handle, unsigned int fourcc, in
                                        NULL);
                }
 
-               _mmcam_dbg_log("vidoesrc new caps set. %"GST_PTR_FORMAT, caps);
-
-               MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
-               gst_caps_unref(caps);
-               caps = NULL;
+               if (caps) {
+                       _mmcam_dbg_log("vidoesrc new caps set. %"GST_PTR_FORMAT, caps);
+                       MMCAMCORDER_G_OBJECT_SET_POINTER(sc->element[_MMCAMCORDER_VIDEOSRC_FILT].gst, "caps", caps);
+                       gst_caps_unref(caps);
+                       caps = NULL;
+               } else {
+                       _mmcam_dbg_err("There are no caps");
+               }
        }
 
        if (hcamcorder->type != MM_CAMCORDER_MODE_AUDIO) {
index df28056..b26fe60 100644 (file)
@@ -427,8 +427,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                                    NULL);
                        if (err_attr_name) {
                                _mmcam_dbg_err("Set %s FAILED.", err_attr_name);
-                               free(err_attr_name);
-                               err_attr_name = NULL;
+                               SAFE_FREE(err_attr_name);
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
                                goto _ERR_DEFAULT_VALUE_INIT;
                        }
@@ -439,8 +438,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                                    NULL);
                        if (err_attr_name) {
                                _mmcam_dbg_err("Get brightness FAILED.");
-                               free(err_attr_name);
-                               err_attr_name = NULL;
+                               SAFE_FREE(err_attr_name);
                                ret = MM_ERROR_CAMCORDER_INTERNAL;
                                goto _ERR_DEFAULT_VALUE_INIT;
                        }
@@ -459,8 +457,7 @@ int _mmcamcorder_create(MMHandleType *handle, MMCamPreset *info)
                                                    NULL);
                if (err_attr_name) {
                        _mmcam_dbg_err("Set %s FAILED.", err_attr_name);
-                       free(err_attr_name);
-                       err_attr_name = NULL;
+                       SAFE_FREE(err_attr_name);
                        ret = MM_ERROR_CAMCORDER_INTERNAL;
                        goto _ERR_DEFAULT_VALUE_INIT;
                }
@@ -1924,6 +1921,7 @@ int _mmcamcorder_init_focusing(MMHandleType handle)
        control = GST_CAMERA_CONTROL (sc->element[_MMCAMCORDER_VIDEOSRC_SRC].gst);
        if (control == NULL) {
                _mmcam_dbg_err("cast CAMERA_CONTROL failed");
+               _MMCAMCORDER_UNLOCK_CMD(hcamcorder);
                return MM_ERROR_CAMCORDER_INTERNAL;
        }
 
@@ -2371,31 +2369,28 @@ _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
        /* alloc info for each mode */
        switch (type) {
        case MM_CAMCORDER_MODE_AUDIO:
-               sc->info_audio = malloc( sizeof(_MMCamcorderAudioInfo));
+               sc->info_audio = g_malloc0( sizeof(_MMCamcorderAudioInfo));
                if(!sc->info_audio) {
                        _mmcam_dbg_err("Failed to alloc info structure");
                        goto ALLOC_SUBCONTEXT_FAILED;
                }
-               memset(sc->info_audio, 0x00, sizeof(_MMCamcorderAudioInfo));
                break;
        case MM_CAMCORDER_MODE_VIDEO_CAPTURE:
        default:
-               sc->info_image = malloc( sizeof(_MMCamcorderImageInfo));
+               sc->info_image = g_malloc0( sizeof(_MMCamcorderImageInfo));
                if(!sc->info_image) {
                        _mmcam_dbg_err("Failed to alloc info structure");
                        goto ALLOC_SUBCONTEXT_FAILED;
                }
-               memset(sc->info_image, 0x00, sizeof(_MMCamcorderImageInfo));
 
                /* init sound status */
                sc->info_image->sound_status = _SOUND_STATUS_INIT;
 
-               sc->info_video = malloc( sizeof(_MMCamcorderVideoInfo));
+               sc->info_video = g_malloc0( sizeof(_MMCamcorderVideoInfo));
                if(!sc->info_video) {
                        _mmcam_dbg_err("Failed to alloc info structure");
                        goto ALLOC_SUBCONTEXT_FAILED;
                }
-               memset(sc->info_video, 0x00, sizeof(_MMCamcorderVideoInfo));
                g_mutex_init(&sc->info_video->size_check_lock);
                break;
        }
@@ -2433,19 +2428,12 @@ _MMCamcorderSubContext *_mmcamcorder_alloc_subcontext(int type)
 
 ALLOC_SUBCONTEXT_FAILED:
        if (sc) {
-               if (sc->info_audio) {
-                       free(sc->info_audio);
-                       sc->info_audio = NULL;
-               }
-               if (sc->info_image) {
-                       free(sc->info_image);
-                       sc->info_image = NULL;
-               }
+               SAFE_G_FREE(sc->info_audio);
+               SAFE_G_FREE(sc->info_image);
                if (sc->info_video) {
                        g_mutex_clear(&sc->info_video->size_check_lock);
-                       free(sc->info_video);
-                       sc->info_video = NULL;
                }
+               SAFE_G_FREE(sc->info_video);
                if (sc->element) {
                        free(sc->element);
                        sc->element = NULL;
@@ -2487,10 +2475,7 @@ void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc)
 
                if (sc->info_video) {
                        _mmcam_dbg_log("release info_video");
-                       if (sc->info_video->filename) {
-                               free(sc->info_video->filename);
-                               sc->info_video->filename = NULL;
-                       }
+                       SAFE_G_FREE(sc->info_video->filename);
                        g_mutex_clear(&sc->info_video->size_check_lock);
                        free(sc->info_video);
                        sc->info_video = NULL;
@@ -2498,10 +2483,7 @@ void _mmcamcorder_dealloc_subcontext(_MMCamcorderSubContext *sc)
 
                if (sc->info_audio) {
                        _mmcam_dbg_log("release info_audio");
-                       if (sc->info_audio->filename) {
-                               free(sc->info_audio->filename);
-                               sc->info_audio->filename = NULL;
-                       }
+                       SAFE_G_FREE(sc->info_audio->filename);
                        free(sc->info_audio);
                        sc->info_audio = NULL;
                }
@@ -2829,13 +2811,10 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                                goto DROP_MESSAGE;
                        }
 
-                       cam_fd_info = (MMCamFaceDetectInfo *)malloc(sizeof(MMCamFaceDetectInfo));
+                       cam_fd_info = (MMCamFaceDetectInfo *)g_malloc(sizeof(MMCamFaceDetectInfo));
                        if (cam_fd_info == NULL) {
                                _mmcam_dbg_warn("cam_fd_info alloc failed");
-
-                               free(fd_info);
-                               fd_info = NULL;
-
+                               SAFE_FREE(fd_info);
                                goto DROP_MESSAGE;
                        }
 
@@ -2843,7 +2822,7 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                        cam_fd_info->num_of_faces = fd_info->num_of_faces;
 
                        if (cam_fd_info->num_of_faces > 0) {
-                               cam_fd_info->face_info = (MMCamFaceInfo *)malloc(sizeof(MMCamFaceInfo) * cam_fd_info->num_of_faces);
+                               cam_fd_info->face_info = (MMCamFaceInfo *)g_malloc(sizeof(MMCamFaceInfo) * cam_fd_info->num_of_faces);
                                if (cam_fd_info->face_info) {
                                        /* set information of each face */
                                        for (i = 0 ; i < fd_info->num_of_faces ; i++) {
@@ -2867,8 +2846,7 @@ GstBusSyncReply _mmcamcorder_pipeline_bus_sync_callback(GstBus *bus, GstMessage
                                        _mmcam_dbg_warn("MMCamFaceInfo alloc failed");
 
                                        /* free allocated memory that is not sent */
-                                       free(cam_fd_info);
-                                       cam_fd_info = NULL;
+                                       SAFE_G_FREE(cam_fd_info);
                                }
                        } else {
                                cam_fd_info->face_info = NULL;
index caa09d7..433282d 100644 (file)
@@ -316,8 +316,7 @@ int _mmcamcorder_image_cmd_capture(MMHandleType handle)
                                    NULL);
        if (err_name) {
                _mmcam_dbg_warn("get_attributes err %s, ret 0x%x", err_name, ret);
-               free(err_name);
-               err_name = NULL;
+               SAFE_FREE(err_name);
        }
 
        ret = MM_ERROR_NONE;
@@ -462,8 +461,7 @@ int _mmcamcorder_image_cmd_capture(MMHandleType handle)
                                                    NULL);
                        if (err_name) {
                                _mmcam_dbg_warn("get_attributes err %s", err_name);
-                               free(err_name);
-                               err_name = NULL;
+                               SAFE_FREE(err_name);
                        }
 
                        /* set new caps */
@@ -501,8 +499,7 @@ int _mmcamcorder_image_cmd_capture(MMHandleType handle)
                                                  NULL);
                if (err_name) {
                        _mmcam_dbg_warn("get_attributes err %s, ret 0x%x", err_name, ret);
-                       free(err_name);
-                       err_name = NULL;
+                       SAFE_FREE(err_name);
                }
 
                /* set JPEG quality */
@@ -716,6 +713,10 @@ int _mmcamcorder_image_cmd_preview_start(MMHandleType handle)
                                                            MMCAM_CAMERA_FPS, &fps,
                                                            MMCAM_CAMERA_ROTATION, &rotation,
                                                            NULL);
+                               if (err_name) {
+                                       _mmcam_dbg_warn("get_attributes err %s, ret 0x%x", err_name, ret);
+                                       SAFE_FREE(err_name);
+                               }
 
                                /* set new caps */
                                ret = _mmcamcorder_set_videosrc_caps(handle, sc->fourcc, width, height, fps, rotation);
index 0ef310a..c2540d8 100644 (file)
@@ -63,7 +63,7 @@
        if (fputs(x_str, x_file) == EOF) \
        {\
                _mmcam_dbg_err("[Critical] fputs() returns fail.\n");\
-               SAFE_FREE(str); \
+               SAFE_G_FREE(str);       \
                return FALSE;\
        }\
 }
@@ -410,7 +410,7 @@ gboolean _mmcamcorder_write_loci(FILE *f, _MMCamcorderLocationInfo info)
        str = str_to_utf8("location_name");
 
        FPUTS_CHECK(str, f); // name
-       SAFE_FREE(str);
+       SAFE_G_FREE(str);
 
        FPUTC_CHECK('\0', f);
        FPUTC_CHECK(0, f);              //role
@@ -426,13 +426,13 @@ gboolean _mmcamcorder_write_loci(FILE *f, _MMCamcorderLocationInfo info)
 
        str = str_to_utf8("Astronomical_body");
        FPUTS_CHECK(str, f);//Astronomical_body
-       SAFE_FREE(str);
+       SAFE_G_FREE(str);
 
        FPUTC_CHECK('\0', f);
 
        str = str_to_utf8("Additional_notes");
        FPUTS_CHECK(str, f); // Additional_notes
-       SAFE_FREE(str);
+       SAFE_G_FREE(str);
 
        FPUTC_CHECK('\0', f);
 
@@ -903,7 +903,7 @@ void _mmcamcorder_remove_buffer_probe(MMHandleType handle, _MMCamcorderHandlerCa
 
                        list = g_list_next(list);
                        hcamcorder->buffer_probes = g_list_remove(hcamcorder->buffer_probes, item);
-                       SAFE_FREE(item);
+                       SAFE_G_FREE(item);
                } else {
                        _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
                        list = g_list_next(list);
@@ -956,7 +956,7 @@ void _mmcamcorder_remove_one_buffer_probe(MMHandleType handle, void *object)
 
                        list = g_list_next(list);
                        hcamcorder->buffer_probes = g_list_remove(hcamcorder->buffer_probes, item);
-                       SAFE_FREE(item);
+                       SAFE_G_FREE(item);
 
                        break;
                } else {
@@ -1006,7 +1006,7 @@ void _mmcamcorder_remove_event_probe(MMHandleType handle, _MMCamcorderHandlerCat
 
                        list = g_list_next(list);
                        hcamcorder->event_probes = g_list_remove(hcamcorder->event_probes, item);
-                       SAFE_FREE(item);
+                       SAFE_G_FREE(item);
                } else {
                        _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
                        list = g_list_next(list);
@@ -1064,7 +1064,7 @@ void _mmcamcorder_disconnect_signal(MMHandleType handle, _MMCamcorderHandlerCate
 
                        list = g_list_next(list);
                        hcamcorder->signals = g_list_remove(hcamcorder->signals, item);
-                       SAFE_FREE(item);
+                       SAFE_G_FREE(item);
                } else {
                        _mmcam_dbg_log("Skip item : [ID : %lu], [Category : %x] ", item->handler_id, item->category);
                        list = g_list_next(list);
@@ -1178,9 +1178,8 @@ MSG_CALLBACK_DONE:
        if (item->id == MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO) {
                MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)item->param.data;
                if (cam_fd_info) {
-                       SAFE_FREE(cam_fd_info->face_info);
-                       free(cam_fd_info);
-                       cam_fd_info = NULL;
+                       SAFE_G_FREE(cam_fd_info->face_info);
+                       SAFE_G_FREE(cam_fd_info);
 
                        item->param.data = NULL;
                        item->param.size = 0;
@@ -1190,12 +1189,9 @@ MSG_CALLBACK_DONE:
                MMCamRecordingReport *report = (MMCamRecordingReport *)item->param.data;
                if (report) {
                        if (report->recording_filename) {
-                               free(report->recording_filename);
-                               report->recording_filename = NULL;
+                               SAFE_G_FREE(report->recording_filename);
                        }
-                       free(report);
-                       report = NULL;
-
+                       SAFE_G_FREE(report);
                        item->param.data = NULL;
                }
        }
@@ -1203,8 +1199,7 @@ MSG_CALLBACK_DONE:
        g_mutex_unlock(&item->lock);
        g_mutex_clear(&item->lock);
 
-       free(item);
-       item = NULL;
+       SAFE_G_FREE(item);
 
        /* For not being called again */
        return FALSE;
@@ -1285,26 +1280,18 @@ gboolean _mmcamcorder_send_message(MMHandleType handle, _MMCamcorderMsgItem *dat
        if (data->id == MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO) {
                MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)data->param.data;
                if (cam_fd_info) {
-                       SAFE_FREE(cam_fd_info->face_info);
-                       free(cam_fd_info);
-                       cam_fd_info = NULL;
-
-                       data->param.data = NULL;
+                       SAFE_G_FREE(cam_fd_info->face_info);
+                       SAFE_G_FREE(cam_fd_info);
                        data->param.size = 0;
                }
        } else if (data->id == MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED ||
                   data->id == MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED) {
                MMCamRecordingReport *report = (MMCamRecordingReport *)data->param.data;
                if (report) {
-                       if (report->recording_filename) {
-                               free(report->recording_filename);
-                               report->recording_filename = NULL;
-                       }
-                       free(report);
-                       report = NULL;
-
+                       SAFE_G_FREE(report->recording_filename);
                        data->param.data = NULL;
                }
+               SAFE_G_FREE(report);
        }
 #endif /* _MMCAMCORDER_ENABLE_IDLE_MESSAGE_CALLBACK */
 
@@ -1353,26 +1340,17 @@ void _mmcamcorder_remove_message_all(MMHandleType handle)
                                        if (item->id == MM_MESSAGE_CAMCORDER_FACE_DETECT_INFO) {
                                                MMCamFaceDetectInfo *cam_fd_info = (MMCamFaceDetectInfo *)item->param.data;
                                                if (cam_fd_info) {
-                                                       SAFE_FREE(cam_fd_info->face_info);
-                                                       free(cam_fd_info);
-                                                       cam_fd_info = NULL;
-
-                                                       item->param.data = NULL;
+                                                       SAFE_G_FREE(cam_fd_info->face_info);
                                                        item->param.size = 0;
                                                }
+                                               SAFE_G_FREE(cam_fd_info);
                                        } else if (item->id == MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED ||
                                                   item->id == MM_MESSAGE_CAMCORDER_AUDIO_CAPTURED) {
                                                MMCamRecordingReport *report = (MMCamRecordingReport *)item->param.data;
                                                if (report) {
-                                                       if (report->recording_filename) {
-                                                               free(report->recording_filename);
-                                                               report->recording_filename = NULL;
-                                                       }
-                                                       free(report);
-                                                       report = NULL;
-
-                                                       item->param.data = NULL;
+                                                       SAFE_G_FREE(report->recording_filename);
                                                }
+                                               SAFE_G_FREE(report);
                                        }
 
                                        hcamcorder->msg_data = g_list_remove(hcamcorder->msg_data, item);
@@ -1382,8 +1360,7 @@ void _mmcamcorder_remove_message_all(MMHandleType handle)
                                        if (ret == TRUE) {
                                                g_mutex_clear(&item->lock);
 
-                                               free(item);
-                                               item = NULL;
+                                               SAFE_G_FREE(item);
 
                                                _mmcam_dbg_log("remove msg done");
                                        }
index 12656b3..df85937 100644 (file)
@@ -1215,11 +1215,11 @@ int _mmcamcorder_video_handle_eos(MMHandleType handle)
 
        /* Send recording report to application */
        msg.id = MM_MESSAGE_CAMCORDER_VIDEO_CAPTURED;
-       report = (MMCamRecordingReport *)malloc(sizeof(MMCamRecordingReport));
+       report = (MMCamRecordingReport *)g_malloc(sizeof(MMCamRecordingReport));
        if (!report) {
                _mmcam_dbg_err("Recording report fail(%s). Out of memory.", info->filename);
        } else {
-               report->recording_filename = strdup(info->filename);
+               report->recording_filename = g_strdup(info->filename);
                msg.param.data= report;
                msg.param.code = 1;
                _mmcamcorder_send_message((MMHandleType)hcamcorder, &msg);
@@ -2048,7 +2048,7 @@ int _mmcamcorder_video_prepare_record(MMHandleType handle)
                                            MMCAM_TARGET_FILENAME, &temp_filename, &size,
                                            NULL);
                if (temp_filename) {
-                       info->filename = strdup(temp_filename);
+                       info->filename = g_strdup(temp_filename);
                }
 
                if (!info->filename) {
index 8f7c12f..f3e0d46 100644 (file)
@@ -182,7 +182,7 @@ do {\
        int ret = 0; \
        ret = expr; \
        if (ret != MM_ERROR_NONE) {\
-               printf("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
+               g_print("[%s:%d] error code : %x \n", __func__, __LINE__, ret); \
                return; \
        }\
 } while(0)
@@ -214,9 +214,12 @@ do { \
 } while(0)
 
 #ifndef SAFE_FREE
-#define SAFE_FREE(x)       if(x) {g_free(x); x = NULL;}
+#define SAFE_FREE(x)       if(x) {free(x); x = NULL;}
 #endif
 
+#ifndef SAFE_G_FREE
+#define SAFE_G_FREE(x)       if(x) {g_free(x); x = NULL;}
+#endif
 
 GTimeVal previous;
 GTimeVal current;
@@ -533,7 +536,7 @@ cam_utils_convert_YUYV_to_UYVY(unsigned char* dst, unsigned char* src, gint leng
 static int camcordertest_audio_stream_cb(MMCamcorderAudioStreamDataType *stream, void *user_param)
 {
        audio_stream_cb_cnt++;
-       printf("audio_stream cb is called (stream:%p, data:%p, format:%d, channel:%d, volume_dB:%f, length:%d, timestamp:%d)\n",
+       g_print("audio_stream cb is called (stream:%p, data:%p, format:%d, channel:%d, volume_dB:%f, length:%d, timestamp:%d)\n",
               stream, stream->data, stream->format, stream->channel, stream->volume_dB, stream->length, stream->timestamp);
 
        return TRUE;
@@ -544,7 +547,7 @@ static int camcordertest_video_stream_cb(MMCamcorderVideoStreamDataType *stream,
 {
        video_stream_cb_cnt++;
 
-       printf("VIDEO STREAM CALLBACK total length :%u, size %dx%d\n", stream->length_total, stream->width, stream->height);
+       g_print("VIDEO STREAM CALLBACK total length :%u, size %dx%d\n", stream->length_total, stream->width, stream->height);
 
        return TRUE;
 }
@@ -554,20 +557,20 @@ static void _file_write(char *path, void *data, int size)
        FILE *fp = NULL;
 
        if (!path || !data || size <= 0) {
-               printf("ERROR %p %p %d\n", path, data, size);
+               g_print("ERROR %p %p %d\n", path, data, size);
                return;
        }
 
        fp = fopen(path, "w");
        if (fp == NULL) {
-               printf("open error! [%s], errno %d\n", path, errno);
+               g_print("open error! [%s], errno %d\n", path, errno);
                return;
        } else {
-               printf("open success [%s]\n", path);
+               g_print("open success [%s]\n", path);
                if (fwrite(data, size, 1, fp) != 1) {
-                       printf("write error! errno %d\n", errno);
+                       g_print("write error! errno %d\n", errno);
                } else {
-                       printf("write success [%s]\n", path);
+                       g_print("write success [%s]\n", path);
                }
 
                fclose(fp);
@@ -580,20 +583,20 @@ static void _file_write2(const char *path, void *data, int size)
        FILE *fp = NULL;
 
        if (!path || !data || size <= 0) {
-               printf("ERROR %p %p %d\n", path, data, size);
+               g_print("ERROR %p %p %d\n", path, data, size);
                return;
        }
 
        fp = fopen(path, "w");
        if (fp == NULL) {
-               printf("open error! [%s], errno %d\n", path, errno);
+               g_print("open error! [%s], errno %d\n", path, errno);
                return;
        } else {
-               printf("open success [%s]\n", path);
+               g_print("open success [%s]\n", path);
                if (fwrite(data, size, 1, fp) != 1) {
-                       printf("write error! errno %d\n", errno);
+                       g_print("write error! errno %d\n", errno);
                } else {
-                       printf("write success [%s]\n", path);
+                       g_print("write success [%s]\n", path);
                }
 
                fclose(fp);
@@ -635,14 +638,12 @@ camcordertest_video_capture_cb(MMCamcorderCaptureDataType *main, MMCamcorderCapt
                if (nret) {
                        _file_write(m_filename, dst, dst_size);
                } else {
-                       printf("Failed to encode YUV(%d) -> JPEG. \n", main->format);
+                       g_print("Failed to encode YUV(%d) -> JPEG. \n", main->format);
                }
-
-               free(dst);
-               dst = NULL;
+               SAFE_FREE(dst);
        } else if (!hcamcorder->isMultishot) {
 
-               printf("MM_PIXEL_FORMAT_ENCODED main->data=%p main->length=%d, main->width=%d, main->heigtht=%d \n",
+               g_print("MM_PIXEL_FORMAT_ENCODED main->data=%p main->length=%d, main->width=%d, main->heigtht=%d \n",
                       main->data, main->length, main->width, main->height);
 
                /* main image */
@@ -660,7 +661,7 @@ camcordertest_video_capture_cb(MMCamcorderCaptureDataType *main, MMCamcorderCapt
                if (scrnl != NULL) {
                        _file_write2(IMAGE_CAPTURE_SCREENNAIL_PATH, scrnl->data, scrnl->length);
                } else {
-                       printf( "Screennail buffer is NULL.\n" );
+                       g_print( "Screennail buffer is NULL.\n" );
                }
 
                /* EXIF data */
@@ -688,7 +689,6 @@ static gboolean test_idle_capture_start()
        if (err < 0) {
                warn_msg_t("Multishot mm_camcorder_capture_start = %x", err);
        }
-
        return FALSE;
 }
 
@@ -737,11 +737,12 @@ int camcordertest_set_attr_xypair(cam_xypair_t pair)
                                                                        NULL);
                        if (err < 0) {
                                err_msg_t("camcordertest_set_attr_xypair : Error(%s:%x)!!", err_attr_name, err);
-                               SAFE_FREE (err_attr_name);
+                               SAFE_FREE(err_attr_name);
                                return FALSE;
                        }
 
                        //success
+                       SAFE_FREE(err_attr_name);
                        return TRUE;
                }
 
@@ -959,10 +960,10 @@ static void main_menu(gchar buf)
                                        if(hcamcorder->isMultishot) {
                                                int interval = 0;
                                                flush_stdin();
-                                               printf("\ninput interval(ms) \n");
+                                               g_print("\ninput interval(ms) \n");
                                                err = scanf("%d", &interval);
                                                if (err == EOF) {
-                                                       printf("\nscanf error : errno %d\n", errno);
+                                                       g_print("\nscanf error : errno %d\n", errno);
                                                        interval = 300;
                                                }
                                                err = mm_camcorder_set_attributes(hcamcorder->camcorder, &err_attr_name,
@@ -970,7 +971,7 @@ static void main_menu(gchar buf)
                                                                                  NULL);
                                                if (err != MM_ERROR_NONE) {
                                                        err_msg_t("Attribute setting fail : (%s:%x)", err_attr_name, err);
-                                                       SAFE_FREE (err_attr_name);
+                                                       SAFE_FREE(err_attr_name);
                                                }
                                        } else {
                                                err = mm_camcorder_set_attributes(hcamcorder->camcorder, &err_attr_name,
@@ -978,7 +979,7 @@ static void main_menu(gchar buf)
                                                                                  NULL);
                                                if (err != MM_ERROR_NONE) {
                                                        err_msg_t("Attribute setting fail : (%s:%x)", err_attr_name, err);
-                                                       SAFE_FREE (err_attr_name);
+                                                       SAFE_FREE(err_attr_name);
                                                }
                                        }
 
@@ -1202,7 +1203,7 @@ static void setting_menu(gchar buf)
                                        }
                                        err = scanf("%d",&idx);
                                        if (err == EOF) {
-                                               printf("\nscanf error : errno %d\n", errno);
+                                               g_print("\nscanf error : errno %d\n", errno);
                                        } else {
                                                if( idx > 0 && idx <= width_count ) {
                                                        //Set capture size first
@@ -1253,7 +1254,7 @@ static void setting_menu(gchar buf)
                                        }
                                        err = scanf("%d",&idx);
                                        if (err == EOF) {
-                                               printf("\nscanf error : errno %d\n", errno);
+                                               g_print("\nscanf error : errno %d\n", errno);
                                        } else {
                                                if( idx > 0 && idx <= width_count ) {
                                                        //Set capture size first
@@ -1933,8 +1934,7 @@ static void setting_menu(gchar buf)
 
                                if( err != MM_ERROR_NONE ) {
                                        g_print( "Failed to set touch AF area.(%x)(%s)\n", err, err_attr_name );
-                                       free( err_attr_name );
-                                       err_attr_name = NULL;
+                                       SAFE_FREE(err_attr_name);
                                } else {
                                        g_print( "Succeed to set touch AF area.\n" );
                                }
@@ -1978,8 +1978,7 @@ static void setting_menu(gchar buf)
                                                                  NULL);
                                if (err != MM_ERROR_NONE) {
                                        g_print("Failed to set Camcorder Motion Rate %f [err:0x%x]\n", motion_rate, err);
-                                       free( err_attr_name );
-                                       err_attr_name = NULL;
+                                       SAFE_FREE(err_attr_name);
                                } else {
                                        g_print("Succeed to set Motion Rate %f\n", motion_rate);
                                }
@@ -1999,12 +1998,11 @@ static void setting_menu(gchar buf)
                hcamcorder->menu_state = MENU_STATE_MAIN;
        }
 
-       if(err_attr_name){
-               free( err_attr_name );
-               err_attr_name = NULL;
-       }
-
        g_print("\t bret : 0x%x \n", bret);
+
+       SAFE_FREE(err_attr_name);
+
+       return;
 }
 
 
@@ -2048,9 +2046,7 @@ static gboolean cmd_input(GIOChannel *channel)
                                break;
                }
 
-               g_free(buf);
-               buf = NULL;
-
+               SAFE_G_FREE(buf);
                print_menu();
        } else {
                debug_msg_t("No read input");
@@ -2061,28 +2057,28 @@ static gboolean cmd_input(GIOChannel *channel)
 
 void validity_print(MMCamAttrsInfo *info)
 {
-                       printf("info(%d,%d, %d))\n", info->type, info->flag, info->validity_type);
-                       if (info->validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_ARRAY)
-                       {
-                               printf("int array(%p, %d)\n", info->int_array.array, info->int_array.count);
-                       }
-                       else if (info->validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_RANGE)
-                       {
-                               printf("int range(%d, %d)\n", info->int_range.min, info->int_range.max);
-                       }
-                       else if (info->validity_type == MM_CAM_ATTRS_VALID_TYPE_DOUBLE_ARRAY)
-                       {
-                               printf("double array(%p, %d)\n", info->double_array.array, info->double_array.count);
-                       }
-                       else if(info->validity_type == MM_CAM_ATTRS_VALID_TYPE_DOUBLE_RANGE)
-                       {
-                               printf("double range(%f, %f)\n", info->double_range.min, info->double_range.max);
-                       }
-                       else
-                       {
-                               printf("validity none\n");
-                       }
-                       return;
+       g_print("info(%d,%d, %d))\n", info->type, info->flag, info->validity_type);
+       if (info->validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_ARRAY)
+       {
+               g_print("int array(%p, %d)\n", info->int_array.array, info->int_array.count);
+       }
+       else if (info->validity_type == MM_CAM_ATTRS_VALID_TYPE_INT_RANGE)
+       {
+               g_print("int range(%d, %d)\n", info->int_range.min, info->int_range.max);
+       }
+       else if (info->validity_type == MM_CAM_ATTRS_VALID_TYPE_DOUBLE_ARRAY)
+       {
+               g_print("double array(%p, %d)\n", info->double_array.array, info->double_array.count);
+       }
+       else if(info->validity_type == MM_CAM_ATTRS_VALID_TYPE_DOUBLE_RANGE)
+       {
+               g_print("double range(%f, %f)\n", info->double_range.min, info->double_range.max);
+       }
+       else
+       {
+               g_print("validity none\n");
+       }
+       return;
 }
 
 
@@ -2170,7 +2166,7 @@ static gboolean init(int type)
 
                if (err != MM_ERROR_NONE) {
                        warn_msg_t("Init fail. (%s:%x)", err_attr_name, err);
-                       SAFE_FREE (err_attr_name);
+                       SAFE_FREE(err_attr_name);
                        goto ERROR;
                }
 
@@ -2200,7 +2196,7 @@ static gboolean init(int type)
 
                if (err < 0) {
                        warn_msg_t("Init fail. (%s:%x)", err_attr_name, err);
-                       SAFE_FREE (err_attr_name);
+                       SAFE_FREE(err_attr_name);
                        goto ERROR;
                }
 
@@ -2208,7 +2204,7 @@ static gboolean init(int type)
                mm_camcorder_set_audio_stream_callback(hcamcorder->camcorder, (mm_camcorder_audio_stream_callback)camcordertest_audio_stream_cb, (void*)hcamcorder->camcorder);
 #endif /* USE_AUDIO_STREAM_CB */
        }
-
+       SAFE_FREE (err_attr_name);
        debug_msg_t("Init DONE.");
 
        return TRUE;