From owner-freebsd-hackers@FreeBSD.ORG Fri Nov 7 19:27:49 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D5D90106564A for ; Fri, 7 Nov 2008 19:27:49 +0000 (UTC) (envelope-from sem@FreeBSD.org) Received: from mail.ciam.ru (mail.ciam.ru [212.34.63.72]) by mx1.freebsd.org (Postfix) with ESMTP id 953C08FC08 for ; Fri, 7 Nov 2008 19:27:49 +0000 (UTC) (envelope-from sem@FreeBSD.org) Received: from dhcp250-210.yandex.ru ([87.250.250.210]) by mail.ciam.ru with esmtpa (Exim 4.x) id 1KyWgK-000NcD-1z for freebsd-hackers@freebsd.org; Fri, 07 Nov 2008 22:07:44 +0300 Message-ID: <491491E5.8090805@FreeBSD.org> Date: Fri, 07 Nov 2008 22:07:17 +0300 From: Sergey Matveychuk User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: LIST_REMOVE problem X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Nov 2008 19:27:49 -0000 Hi! I wonder how this example from queue(3) works: while (!LIST_EMPTY(&head)) { /* List Deletion. */ n1 = LIST_FIRST(&head); LIST_REMOVE(n1, entries); free(n1); } If we'll take a look at code, LIST_REMOVE don't change a head pointer if you remove the first element: #define LIST_FIRST(head) ((head)->lh_first) ... #define LIST_REMOVE(elm, field) do { \ if (LIST_NEXT((elm), field) != NULL) \ LIST_NEXT((elm), field)->field.le_prev = \ (elm)->field.le_prev; \ *(elm)->field.le_prev = LIST_NEXT((elm), field); \ } while (0) So n1 in the example above will point to removed (and freed) element. -- Dixi. Sem.