私はCに慣れていません。malloc + freeに慣れようとしています。
私は次の構造を持っています:
typedef struct {
GstElement* pipeline;
GFile* file;
char* filename;
} Record;
構造体にメモリを割り当て、データを割り当てます。
Record* record_start (const char* filename)
{
GstElement *pipeline;
GFile* file;
char* path;
pipeline = gst_pipeline_new ("pipeline", NULL);
/* Same code */
path = g_strdup_printf ("%s.%s", filename, gm_audio_profile_get_extension (profile));
file = g_file_new_for_path (path);
Record *record = g_malloc0 (sizeof (Record));
record->file = file;
record->filename = path;
record->pipeline = pipeline;
return record;
}
次に、割り当てられたすべてのメモリを解放しようとします。
void record_stop (Record *record)
{
g_assert(record);
/* Same code */
gst_object_unref (record->pipeline));
g_clear_object (&record->file);
g_free (record->filename);
g_free (record);
}
メモリは解放されましたか?