summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno da Silva Belo <brunodasilvabelo@gmail.com>2019-10-07 09:02:10 -0400
committerMike Blumenkrantz <zmike@samsung.com>2019-10-07 09:02:10 -0400
commitf18a5b4389d1ed779998c9f07901fb49db28b279 (patch)
tree21e536806ce7aa35c33a589fd528bea00b1a26c9
parent55e865dd82a97ae582574fea9db0c028174498e3 (diff)
c: coverity: resource leaked when using realloc.
Summary: from https://en.cppreference.com/w/c/memory/realloc ``` On success, returns the pointer to the beginning of newly allocated memory. To avoid a memory leak, the returned pointer must be deallocated with free() or realloc(). The original pointer ptr is invalidated and any access to it is undefined behavior (even if reallocation was in-place). On failure, returns a null pointer. The original pointer ptr remains valid and may need to be deallocated with free() or realloc(). ``` So a temporary to test if `realloc` failed then use the original pointer to use `free`. `CID1404749` `CID1404741` Reviewers: lauromoura, felipealmeida, zmike Reviewed By: zmike Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D10284
-rw-r--r--src/lib/elementary/efl_ui_caching_factory.c19
-rw-r--r--src/lib/elementary/efl_ui_widget_factory.c17
2 files changed, 23 insertions, 13 deletions
diff --git a/src/lib/elementary/efl_ui_caching_factory.c b/src/lib/elementary/efl_ui_caching_factory.c
index 7dbfc0a..5c714d9 100644
--- a/src/lib/elementary/efl_ui_caching_factory.c
+++ b/src/lib/elementary/efl_ui_caching_factory.c
@@ -201,15 +201,15 @@ _efl_ui_caching_factory_efl_ui_factory_create(Eo *obj,
201 Efl_Ui_Caching_Factory_Data *pd, 201 Efl_Ui_Caching_Factory_Data *pd,
202 Eina_Iterator *models) 202 Eina_Iterator *models)
203{ 203{
204 Efl_Ui_Caching_Factory_Request *r; 204 Efl_Ui_Caching_Factory_Request *r = NULL;
205 Efl_Ui_Caching_Factory_Group_Request *gr; 205 Efl_Ui_Caching_Factory_Group_Request *gr = NULL;
206 Efl_Gfx_Entity *w = NULL; 206 Efl_Gfx_Entity *w = NULL;
207 Efl_Model *model; 207 Efl_Model *model = NULL;
208 Eina_Future *f; 208 Eina_Future *f = NULL;
209 209
210 if (pd->cache && pd->style && !pd->klass) 210 if (pd->cache && pd->style && !pd->klass)
211 { 211 {
212 Eina_Future **all; 212 Eina_Future **all = NULL;
213 int count = 0; 213 int count = 0;
214 214
215 r = calloc(1, sizeof (Efl_Ui_Caching_Factory_Request)); 215 r = calloc(1, sizeof (Efl_Ui_Caching_Factory_Request));
@@ -228,8 +228,13 @@ _efl_ui_caching_factory_efl_ui_factory_create(Eo *obj,
228 .success = _efl_ui_caching_factory_create_then, 228 .success = _efl_ui_caching_factory_create_then,
229 .data = r); 229 .data = r);
230 230
231 all = realloc(all, (count + 1) * sizeof (Eina_Future *)); 231 Eina_Future **tmp = realloc(all, (count + 1) * sizeof (Eina_Future *));
232 if (!all) goto alloc_array_error; 232 if (!tmp)
233 {
234 free(all);
235 goto alloc_array_error;
236 }
237 all = tmp;
233 } 238 }
234 eina_iterator_free(models); 239 eina_iterator_free(models);
235 240
diff --git a/src/lib/elementary/efl_ui_widget_factory.c b/src/lib/elementary/efl_ui_widget_factory.c
index 13160af..5ab9477 100644
--- a/src/lib/elementary/efl_ui_widget_factory.c
+++ b/src/lib/elementary/efl_ui_widget_factory.c
@@ -267,9 +267,9 @@ static Eina_Future *
267_efl_ui_widget_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Widget_Factory_Data *pd, 267_efl_ui_widget_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Widget_Factory_Data *pd,
268 Eina_Iterator *models) 268 Eina_Iterator *models)
269{ 269{
270 Efl_Ui_Widget_Factory_Request *r; 270 Efl_Ui_Widget_Factory_Request *r = NULL;
271 Eina_Future **f; 271 Eina_Future **f = NULL;
272 Efl_Model *model; 272 Efl_Model *model = NULL;
273 int count = 0; 273 int count = 0;
274 274
275 if (!pd->klass) 275 if (!pd->klass)
@@ -277,7 +277,7 @@ _efl_ui_widget_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Widget_Factory_Data
277 277
278 if (!pd->style) 278 if (!pd->style)
279 { 279 {
280 Efl_Ui_Widget *w; 280 Efl_Ui_Widget *w = NULL;
281 Eina_Value r; 281 Eina_Value r;
282 282
283 eina_value_array_setup(&r, EINA_VALUE_TYPE_OBJECT, 4); 283 eina_value_array_setup(&r, EINA_VALUE_TYPE_OBJECT, 4);
@@ -309,8 +309,13 @@ _efl_ui_widget_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Widget_Factory_Data
309 .success = _efl_ui_widget_factory_create_then, 309 .success = _efl_ui_widget_factory_create_then,
310 .free = _efl_ui_widget_factory_single_cleanup); 310 .free = _efl_ui_widget_factory_single_cleanup);
311 311
312 f = realloc(f, (count + 1) * sizeof (Eina_Future *)); 312 Eina_Future** tmp = realloc(f, (count + 1) * sizeof (Eina_Future *));
313 if (!f) goto alloc_array_error; 313 if (!tmp)
314 {
315 free(f);
316 goto alloc_array_error;
317 }
318 f = tmp;
314 } 319 }
315 eina_iterator_free(models); 320 eina_iterator_free(models);
316 321