summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2012-10-19 19:33:48 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2012-10-19 19:33:48 +0000
commitcd6a78ac6e1686d83bba56f83ba2c92b6105830e (patch)
treee573ce2300378d76e753c6c102847c72e6ea7acc
parent57883450b86f02a53f08c630141bf8d7db55c358 (diff)
etrophy free functions now take NULL more gracefully, also add NULL checks in a couple other important places
SVN revision: 78267
-rw-r--r--src/lib/etrophy.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/lib/etrophy.c b/src/lib/etrophy.c
index b98de74..c700454 100644
--- a/src/lib/etrophy.c
+++ b/src/lib/etrophy.c
@@ -151,7 +151,7 @@ etrophy_trophy_new(const char *name, const char *description, Etrophy_Trophy_Vis
151EAPI void 151EAPI void
152etrophy_trophy_free(Etrophy_Trophy *trophy) 152etrophy_trophy_free(Etrophy_Trophy *trophy)
153{ 153{
154 EINA_SAFETY_ON_NULL_RETURN(trophy); 154 if (!trophy) return;
155 eina_stringshare_del(trophy->name); 155 eina_stringshare_del(trophy->name);
156 eina_stringshare_del(trophy->description); 156 eina_stringshare_del(trophy->description);
157 free(trophy); 157 free(trophy);
@@ -265,7 +265,7 @@ etrophy_lock_new(const char *name, Etrophy_Lock_State state)
265EAPI void 265EAPI void
266etrophy_lock_free(Etrophy_Lock *lock) 266etrophy_lock_free(Etrophy_Lock *lock)
267{ 267{
268 EINA_SAFETY_ON_NULL_RETURN(lock); 268 if (!lock) return;
269 eina_stringshare_del(lock->name); 269 eina_stringshare_del(lock->name);
270 free(lock); 270 free(lock);
271} 271}
@@ -349,7 +349,7 @@ etrophy_score_new(const char *player_name, int score)
349EAPI void 349EAPI void
350etrophy_score_free(Etrophy_Score *escore) 350etrophy_score_free(Etrophy_Score *escore)
351{ 351{
352 EINA_SAFETY_ON_NULL_RETURN(escore); 352 if (!escore) return;
353 eina_stringshare_del(escore->player_name); 353 eina_stringshare_del(escore->player_name);
354 free(escore); 354 free(escore);
355} 355}
@@ -422,7 +422,7 @@ etrophy_level_new(const char *name)
422EAPI void 422EAPI void
423etrophy_level_free(Etrophy_Level *level) 423etrophy_level_free(Etrophy_Level *level)
424{ 424{
425 EINA_SAFETY_ON_NULL_RETURN(level); 425 if (!level) return;
426 eina_stringshare_del(level->name); 426 eina_stringshare_del(level->name);
427 if (level->scores) 427 if (level->scores)
428 { 428 {
@@ -452,6 +452,7 @@ EAPI inline void
452etrophy_level_score_add(Etrophy_Level *level, Etrophy_Score *escore) 452etrophy_level_score_add(Etrophy_Level *level, Etrophy_Score *escore)
453{ 453{
454 EINA_SAFETY_ON_NULL_RETURN(level); 454 EINA_SAFETY_ON_NULL_RETURN(level);
455 EINA_SAFETY_ON_NULL_RETURN(escore);
455 level->scores = eina_list_sorted_insert(level->scores, _score_cmp, escore); 456 level->scores = eina_list_sorted_insert(level->scores, _score_cmp, escore);
456} 457}
457 458
@@ -459,6 +460,7 @@ EAPI inline void
459etrophy_level_score_del(Etrophy_Level *level, Etrophy_Score *escore) 460etrophy_level_score_del(Etrophy_Level *level, Etrophy_Score *escore)
460{ 461{
461 EINA_SAFETY_ON_NULL_RETURN(level); 462 EINA_SAFETY_ON_NULL_RETURN(level);
463 EINA_SAFETY_ON_NULL_RETURN(escore);
462 level->scores = eina_list_remove(level->scores, escore); 464 level->scores = eina_list_remove(level->scores, escore);
463} 465}
464 466
@@ -553,25 +555,22 @@ etrophy_gamescore_new(const char *gamename)
553EAPI void 555EAPI void
554etrophy_gamescore_free(Etrophy_Gamescore *gamescore) 556etrophy_gamescore_free(Etrophy_Gamescore *gamescore)
555{ 557{
556 EINA_SAFETY_ON_NULL_RETURN(gamescore); 558 if (!gamescore) return;
557 if (gamescore->levels) 559 {
558 { 560 Etrophy_Level *levels_elem;
559 Etrophy_Level *levels_elem; 561 EINA_LIST_FREE (gamescore->levels, levels_elem)
560 EINA_LIST_FREE (gamescore->levels, levels_elem) 562 etrophy_level_free(levels_elem);
561 etrophy_level_free(levels_elem); 563 }
562 } 564 {
563 if (gamescore->trophies) 565 Etrophy_Trophy *trophies_elem;
564 { 566 EINA_LIST_FREE (gamescore->trophies, trophies_elem)
565 Etrophy_Trophy *trophies_elem; 567 etrophy_trophy_free(trophies_elem);
566 EINA_LIST_FREE (gamescore->trophies, trophies_elem) 568 }
567 etrophy_trophy_free(trophies_elem); 569 {
568 } 570 Etrophy_Lock *locks_elem;
569 if (gamescore->locks) 571 EINA_LIST_FREE (gamescore->locks, locks_elem)
570 { 572 etrophy_lock_free(locks_elem);
571 Etrophy_Lock *locks_elem; 573 }
572 EINA_LIST_FREE (gamescore->locks, locks_elem)
573 etrophy_lock_free(locks_elem);
574 }
575 free(gamescore); 574 free(gamescore);
576} 575}
577 576
@@ -579,6 +578,7 @@ EAPI inline void
579etrophy_gamescore_level_add(Etrophy_Gamescore *gamescore, Etrophy_Level *level) 578etrophy_gamescore_level_add(Etrophy_Gamescore *gamescore, Etrophy_Level *level)
580{ 579{
581 EINA_SAFETY_ON_NULL_RETURN(gamescore); 580 EINA_SAFETY_ON_NULL_RETURN(gamescore);
581 EINA_SAFETY_ON_NULL_RETURN(level);
582 gamescore->levels = eina_list_append(gamescore->levels, level); 582 gamescore->levels = eina_list_append(gamescore->levels, level);
583} 583}
584 584
@@ -586,6 +586,7 @@ EAPI inline void
586etrophy_gamescore_level_del(Etrophy_Gamescore *gamescore, Etrophy_Level *level) 586etrophy_gamescore_level_del(Etrophy_Gamescore *gamescore, Etrophy_Level *level)
587{ 587{
588 EINA_SAFETY_ON_NULL_RETURN(gamescore); 588 EINA_SAFETY_ON_NULL_RETURN(gamescore);
589 EINA_SAFETY_ON_NULL_RETURN(level);
589 gamescore->levels = eina_list_remove(gamescore->levels, level); 590 gamescore->levels = eina_list_remove(gamescore->levels, level);
590} 591}
591 592
@@ -625,6 +626,7 @@ EAPI inline void
625etrophy_gamescore_trophy_add(Etrophy_Gamescore *gamescore, Etrophy_Trophy *trophy) 626etrophy_gamescore_trophy_add(Etrophy_Gamescore *gamescore, Etrophy_Trophy *trophy)
626{ 627{
627 EINA_SAFETY_ON_NULL_RETURN(gamescore); 628 EINA_SAFETY_ON_NULL_RETURN(gamescore);
629 EINA_SAFETY_ON_NULL_RETURN(trophy);
628 gamescore->trophies = eina_list_append(gamescore->trophies, trophy); 630 gamescore->trophies = eina_list_append(gamescore->trophies, trophy);
629} 631}
630 632
@@ -632,6 +634,7 @@ EAPI inline void
632etrophy_gamescore_trophy_del(Etrophy_Gamescore *gamescore, Etrophy_Trophy *trophy) 634etrophy_gamescore_trophy_del(Etrophy_Gamescore *gamescore, Etrophy_Trophy *trophy)
633{ 635{
634 EINA_SAFETY_ON_NULL_RETURN(gamescore); 636 EINA_SAFETY_ON_NULL_RETURN(gamescore);
637 EINA_SAFETY_ON_NULL_RETURN(trophy);
635 gamescore->trophies = eina_list_remove(gamescore->trophies, trophy); 638 gamescore->trophies = eina_list_remove(gamescore->trophies, trophy);
636} 639}
637 640
@@ -671,6 +674,7 @@ EAPI inline void
671etrophy_gamescore_lock_add(Etrophy_Gamescore *gamescore, Etrophy_Lock *lock) 674etrophy_gamescore_lock_add(Etrophy_Gamescore *gamescore, Etrophy_Lock *lock)
672{ 675{
673 EINA_SAFETY_ON_NULL_RETURN(gamescore); 676 EINA_SAFETY_ON_NULL_RETURN(gamescore);
677 EINA_SAFETY_ON_NULL_RETURN(lock);
674 gamescore->locks = eina_list_append(gamescore->locks, lock); 678 gamescore->locks = eina_list_append(gamescore->locks, lock);
675} 679}
676 680
@@ -678,6 +682,7 @@ EAPI inline void
678etrophy_gamescore_lock_del(Etrophy_Gamescore *gamescore, Etrophy_Lock *lock) 682etrophy_gamescore_lock_del(Etrophy_Gamescore *gamescore, Etrophy_Lock *lock)
679{ 683{
680 EINA_SAFETY_ON_NULL_RETURN(gamescore); 684 EINA_SAFETY_ON_NULL_RETURN(gamescore);
685 EINA_SAFETY_ON_NULL_RETURN(lock);
681 gamescore->locks = eina_list_remove(gamescore->locks, lock); 686 gamescore->locks = eina_list_remove(gamescore->locks, lock);
682} 687}
683 688