我是 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);
}
内存被释放了吗?