summaryrefslogtreecommitdiff
path: root/src/modules/evas/model_loaders
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-12-19 12:03:46 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-12-19 12:06:24 +0900
commit72f98a06499cbabc7f56290afa89f7b8b37f52b9 (patch)
treeeeb6e690b6c41f210347604683ac0cee5dd63e9d /src/modules/evas/model_loaders
parent34c28918d52b80239f10cd7821aee8ea59f84d47 (diff)
evas/ply: Fix some memleaks
I have a strong feeling that this parser is not very robust... Closes T5001
Diffstat (limited to 'src/modules/evas/model_loaders')
-rw-r--r--src/modules/evas/model_loaders/ply/evas_model_load_ply.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/modules/evas/model_loaders/ply/evas_model_load_ply.c b/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
index eb4228b..9f49039 100644
--- a/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
+++ b/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
@@ -53,18 +53,20 @@ _read_ply_header(char *map, Evas_Model_Load_Save_Header *header)
53 53
54 if (helping_pointer == NULL) 54 if (helping_pointer == NULL)
55 { 55 {
56 ERR("File have not kayword vertex. It is necessary."); 56 ERR("PLY file doesn't contain the required keyword 'vertex'");
57 return EINA_FALSE; 57 return EINA_FALSE;
58 } 58 }
59 59
60 sscanf(helping_pointer[1], "%d", &header->vertices_count); 60 sscanf(helping_pointer[1], "%d", &header->vertices_count);
61 61
62 free(helping_pointer[0]);
62 free(helping_pointer); 63 free(helping_pointer);
64
63 helping_pointer = eina_str_split(map, "end_header\n", 0); 65 helping_pointer = eina_str_split(map, "end_header\n", 0);
64 66
65 if (helping_pointer == NULL) 67 if (helping_pointer == NULL)
66 { 68 {
67 ERR("File have not kayword end_header. It is necessary."); 69 ERR("PLY file doesn't contain the required keyword 'end_header'");
68 return EINA_FALSE; 70 return EINA_FALSE;
69 } 71 }
70 72
@@ -98,14 +100,26 @@ _read_ply_header(char *map, Evas_Model_Load_Save_Header *header)
98 100
99 header->indices_count = 3 * triangles; 101 header->indices_count = 3 * triangles;
100 102
103 free(helping_pointer[0]);
104 free(helping_pointer);
105
101 /* analyse flags used when file was saved in blender */ 106 /* analyse flags used when file was saved in blender */
102 helping_pointer = eina_str_split(map, "property float ", 0); 107 helping_pointer = eina_str_split(map, "property float ", 0);
103 108
109 if (helping_pointer == NULL)
110 return EINA_FALSE;
111
104 if ((helping_pointer[1] != NULL) && (*helping_pointer[1] == 'x') && 112 if ((helping_pointer[1] != NULL) && (*helping_pointer[1] == 'x') &&
105 (helping_pointer[2] != NULL) && (*helping_pointer[2] == 'y') && 113 (helping_pointer[2] != NULL) && (*helping_pointer[2] == 'y') &&
106 (helping_pointer[3] != NULL) && (*helping_pointer[3] == 'z')) 114 (helping_pointer[3] != NULL) && (*helping_pointer[3] == 'z'))
107 header->existence_of_positions = EINA_TRUE; 115 header->existence_of_positions = EINA_TRUE;
108 else return EINA_FALSE; 116 else
117 {
118 ERR("PLY file doesn't start with x,y,z float fields, they are required.");
119 free(helping_pointer[0]);
120 free(helping_pointer);
121 return EINA_FALSE;
122 }
109 123
110 if ((helping_pointer[4] != NULL) && (*helping_pointer[4] == 'n') && 124 if ((helping_pointer[4] != NULL) && (*helping_pointer[4] == 'n') &&
111 (helping_pointer[5] != NULL) && (*helping_pointer[5] == 'n') && 125 (helping_pointer[5] != NULL) && (*helping_pointer[5] == 'n') &&
@@ -120,20 +134,22 @@ _read_ply_header(char *map, Evas_Model_Load_Save_Header *header)
120 (helping_pointer[5] != NULL) && (*helping_pointer[5] == 't')))) 134 (helping_pointer[5] != NULL) && (*helping_pointer[5] == 't'))))
121 header->existence_of_tex_coords = EINA_TRUE; 135 header->existence_of_tex_coords = EINA_TRUE;
122 136
137 free(helping_pointer[0]);
138 free(helping_pointer);
139
123 helping_pointer = eina_str_split(map, "property uchar ", 0); 140 helping_pointer = eina_str_split(map, "property uchar ", 0);
124 141
142 if (helping_pointer == NULL)
143 return EINA_FALSE;
144
125 if ((helping_pointer[1] != NULL) && (*helping_pointer[1] == 'r') && 145 if ((helping_pointer[1] != NULL) && (*helping_pointer[1] == 'r') &&
126 (helping_pointer[2] != NULL) && (*helping_pointer[2] == 'g') && 146 (helping_pointer[2] != NULL) && (*helping_pointer[2] == 'g') &&
127 (helping_pointer[3] != NULL) && (*helping_pointer[3] == 'b')) 147 (helping_pointer[3] != NULL) && (*helping_pointer[3] == 'b'))
128 header->existence_of_colors = EINA_TRUE; 148 header->existence_of_colors = EINA_TRUE;
129 149
130 if (!header->existence_of_positions) 150 free(helping_pointer[0]);
131 {
132 ERR("File have not x, y, or z field as the first 3 float fields. They are necessary.");
133 return EINA_FALSE;
134 }
135
136 free(helping_pointer); 151 free(helping_pointer);
152
137 return EINA_TRUE; 153 return EINA_TRUE;
138} 154}
139 155