struct t_config_file config_file_new struct t_weechat_plugin plugin ch

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
struct t_config_file *
config_file_new (struct t_weechat_plugin *plugin, char *filename)
{
struct t_config_file *new_config_file;
if (!filename)
return NULL;
/* it's NOT authorized to create two config files with same filename */
if (config_file_search (filename))
return NULL;
new_config_file = (struct t_config_file *)malloc (sizeof (struct t_config_file));
- if (new_config_file)
- {
+ if (!new_config_file)
+ goto fail;
+
new_config_file->plugin = plugin;
new_config_file->filename = strdup (filename);
+ if (!new_config_file->filename)
+ goto fail;
new_config_file->file = NULL;
new_config_file->sections = NULL;
new_config_file->last_section = NULL;
new_config_file->prev_config = last_config_file;
new_config_file->next_config = NULL;
if (config_files)
last_config_file->next_config = new_config_file;
else
config_files = new_config_file;
last_config_file = new_config_file;
- }
return new_config_file;
+fail:
+ if (new_config_file)
+ free(new_config_file->filename);
+ free(new_config_file);
+ return NULL;
}