[syslinux:lwip] thread: free(NULL) is safe, lmalloc() always return para-aligned

syslinux-bot for H. Peter Anvin hpa at zytor.com
Fri Apr 22 20:06:23 PDT 2011


Commit-ID:  4dde6f6df7d830842010d3fc35b5fb948bc834f9
Gitweb:     http://syslinux.zytor.com/commit/4dde6f6df7d830842010d3fc35b5fb948bc834f9
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Fri, 22 Apr 2011 19:29:09 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Fri, 22 Apr 2011 19:29:09 -0700

thread: free(NULL) is safe, lmalloc() always return para-aligned

free(NULL) is safe and permitted, no reason to conditionalize calling
free().

lmalloc() will always return a paragraph-aligned memory block, so we
don't have to play games with the offset.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 core/thread/exit_thread.c  |    8 +++-----
 core/thread/start_thread.c |    2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/core/thread/exit_thread.c b/core/thread/exit_thread.c
index 444f9e2..4da224b 100644
--- a/core/thread/exit_thread.c
+++ b/core/thread/exit_thread.c
@@ -14,11 +14,9 @@ __noreturn __exit_thread(void)
     curr->list.prev->next = curr->list.next;
     curr->list.next->prev = curr->list.prev;
 
-    /* Free allocated stacks */
-    if (curr->stack)
-	free(curr->stack);
-    if (curr->rmstack)
-	free(curr->stack);
+    /* Free allocated stacks (note: free(NULL) is permitted and safe). */
+    free(curr->stack);
+    free(curr->stack);
 
     /*
      * Note: __schedule() can explictly handle the case where
diff --git a/core/thread/start_thread.c b/core/thread/start_thread.c
index 77dc0ea..dd2a4de 100644
--- a/core/thread/start_thread.c
+++ b/core/thread/start_thread.c
@@ -49,7 +49,7 @@ struct thread *start_thread(const char *name, size_t stack_size, int prio,
 
     sp->errno = 0;
     sp->rmss = SEG(rmstack);
-    sp->rmsp = OFFS_WRT(rmstack + REAL_MODE_STACK_SIZE, sp->rmss);
+    sp->rmsp = REAL_MODE_STACK_SIZE;
     sp->esi = (size_t)start_func;
     sp->edi = (size_t)func_arg;
     sp->ebx = irq_state();	/* Inherit the IRQ state from the spawner */



More information about the Syslinux-commits mailing list