Merged revisions 328717 via svnmerge from
[asterisk/asterisk.git] / include / asterisk / linkedlists.h
index 8e86470..4c9e27b 100644 (file)
@@ -838,7 +838,10 @@ struct {                                                           \
  */
 #define AST_LIST_REMOVE(head, elm, field) ({                           \
        __typeof(elm) __res = NULL; \
-       if ((head)->first == (elm)) {                                   \
+       __typeof(elm) __tmp = elm; \
+       if (!__tmp) { \
+               __res = NULL; \
+       } else if ((head)->first == (elm)) {                                    \
                __res = (head)->first;                      \
                (head)->first = (elm)->field.next;                      \
                if ((head)->last == (elm))                      \
@@ -854,7 +857,9 @@ struct {                                                            \
                                (head)->last = curelm;                          \
                } \
        }                                                               \
-       (elm)->field.next = NULL;                                       \
+       if (__res) { \
+               (__res)->field.next = NULL; \
+       } \
        (__res); \
 })