Commit 965129b5b760e42bdb825504770c468e8762d8e1

Con Kolivas 2013-05-02T17:26:59

Duplicate the name string always in api_add_data_full to not need persistent storage for names passed to it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/api.c b/api.c
index 427ef07..d19daff 100644
--- a/api.c
+++ b/api.c
@@ -827,7 +827,7 @@ static struct api_data *api_add_data_full(struct api_data *root, char *name, enu
 
 	api_data = (struct api_data *)malloc(sizeof(struct api_data));
 
-	api_data->name = name;
+	api_data->name = strdup(name);
 	api_data->type = type;
 
 	if (root == NULL) {
@@ -1116,6 +1116,7 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
 
 		buf = strchr(buf, '\0');
 
+		free(root->name);
 		if (root->data_was_malloc)
 			free(root->data);