summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2017-02-28 16:00:45 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-02-28 16:00:45 +0900
commit1cbd32aca1e895bccef333398f8b23d6d41d845a (patch)
tree08bc64bd4db0824240e2c3a3cf49fc3382f40af3 /src/lib/eina
parent02bff22d8f78450e8284e53618150bc258863c3e (diff)
eina:list: Fix resource leak
Summary: The usage of the macro EINA_MAGIC_CHECK_LIST can lead (in some cases) to leaks. Signed-off-by: Flavio Ceolin <flavio.ceolin@gmail.com> Reviewers: jpeg Reviewed By: jpeg Subscribers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D4679
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_list.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/lib/eina/eina_list.c b/src/lib/eina/eina_list.c
index 26cf3c8d50..979e484aa4 100644
--- a/src/lib/eina/eina_list.c
+++ b/src/lib/eina/eina_list.c
@@ -100,6 +100,15 @@ static const char EINA_MAGIC_LIST_ACCOUNTING_STR[] = "Eina List Accounting";
100 } \ 100 } \
101 } while(0) 101 } while(0)
102 102
103#define EINA_MAGIC_CHECK_LIST_GOTO(d, label) \
104 do { \
105 if (!EINA_MAGIC_CHECK(d, EINA_MAGIC_LIST)) \
106 { \
107 EINA_MAGIC_FAIL(d, EINA_MAGIC_LIST); \
108 goto label; \
109 } \
110 } while(0)
111
103#define EINA_MAGIC_CHECK_LIST_ITERATOR(d, ...) \ 112#define EINA_MAGIC_CHECK_LIST_ITERATOR(d, ...) \
104 do { \ 113 do { \
105 if (!EINA_MAGIC_CHECK(d, EINA_MAGIC_LIST_ITERATOR)) \ 114 if (!EINA_MAGIC_CHECK(d, EINA_MAGIC_LIST_ITERATOR)) \
@@ -577,7 +586,7 @@ eina_list_append(Eina_List *list, const void *data)
577 return _eina_list_setup_accounting(new_l); 586 return _eina_list_setup_accounting(new_l);
578 } 587 }
579 588
580 EINA_MAGIC_CHECK_LIST(list, NULL); 589 EINA_MAGIC_CHECK_LIST_GOTO(list, on_error);
581 590
582 l = list->accounting->last; 591 l = list->accounting->last;
583 list->accounting->last = new_l; 592 list->accounting->last = new_l;
@@ -587,6 +596,10 @@ eina_list_append(Eina_List *list, const void *data)
587 596
588 _eina_list_update_accounting(list, new_l); 597 _eina_list_update_accounting(list, new_l);
589 return list; 598 return list;
599
600on_error:
601 _eina_list_mempool_list_free(new_l);
602 return NULL;
590} 603}
591 604
592EAPI Eina_List * 605EAPI Eina_List *
@@ -604,13 +617,17 @@ eina_list_prepend(Eina_List *list, const void *data)
604 if (!list) 617 if (!list)
605 return _eina_list_setup_accounting(new_l); 618 return _eina_list_setup_accounting(new_l);
606 619
607 EINA_MAGIC_CHECK_LIST(list, NULL); 620 EINA_MAGIC_CHECK_LIST_GOTO(list, on_error);
608 621
609 list->prev = new_l; 622 list->prev = new_l;
610 623
611 _eina_list_update_accounting(list, new_l); 624 _eina_list_update_accounting(list, new_l);
612 625
613 return new_l; 626 return new_l;
627
628on_error:
629 _eina_list_mempool_list_free(new_l);
630 return NULL;
614} 631}
615 632
616EAPI Eina_List * 633EAPI Eina_List *
@@ -643,10 +660,11 @@ eina_list_append_relative_list(Eina_List *list,
643 if ((!list) || (!relative)) 660 if ((!list) || (!relative))
644 return eina_list_append(list, data); 661 return eina_list_append(list, data);
645 662
663 EINA_MAGIC_CHECK_LIST(relative, NULL);
664
646 new_l = _eina_list_mempool_list_new(list); 665 new_l = _eina_list_mempool_list_new(list);
647 if (!new_l) return list; 666 if (!new_l) return list;
648 667
649 EINA_MAGIC_CHECK_LIST(relative, NULL);
650 new_l->next = relative->next; 668 new_l->next = relative->next;
651 new_l->data = (void *)data; 669 new_l->data = (void *)data;
652 670
@@ -693,11 +711,11 @@ eina_list_prepend_relative_list(Eina_List *list,
693 if ((!list) || (!relative)) 711 if ((!list) || (!relative))
694 return eina_list_prepend(list, data); 712 return eina_list_prepend(list, data);
695 713
714 EINA_MAGIC_CHECK_LIST(relative, NULL);
715
696 new_l = _eina_list_mempool_list_new(list); 716 new_l = _eina_list_mempool_list_new(list);
697 if (!new_l) return list; 717 if (!new_l) return list;
698 718
699 EINA_MAGIC_CHECK_LIST(relative, NULL);
700
701 new_l->prev = relative->prev; 719 new_l->prev = relative->prev;
702 new_l->next = relative; 720 new_l->next = relative;
703 new_l->data = (void *)data; 721 new_l->data = (void *)data;