Module Name:    src
Committed By:   pooka
Date:           Wed Jun  2 18:15:35 UTC 2010

Modified Files:
        src/lib/librumpuser: rumpuser.c

Log Message:
Check return value of posix_memalign ... always helpful to not return
garbage memory in case of failure.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/librumpuser/rumpuser.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpuser/rumpuser.c
diff -u src/lib/librumpuser/rumpuser.c:1.5 src/lib/librumpuser/rumpuser.c:1.6
--- src/lib/librumpuser/rumpuser.c:1.5	Tue Jun  1 20:11:33 2010
+++ src/lib/librumpuser/rumpuser.c	Wed Jun  2 18:15:35 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser.c,v 1.5 2010/06/01 20:11:33 pooka Exp $	*/
+/*	$NetBSD: rumpuser.c,v 1.6 2010/06/02 18:15:35 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.5 2010/06/01 20:11:33 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.6 2010/06/02 18:15:35 pooka Exp $");
 #endif /* !lint */
 
 /* thank the maker for this */
@@ -196,11 +196,20 @@
 rumpuser_malloc(size_t howmuch, int alignment)
 {
 	void *mem;
+	int rv;
 
 	if (alignment == 0)
 		alignment = sizeof(void *);
 
-	posix_memalign(&mem, alignment, howmuch);
+	rv = posix_memalign(&mem, alignment, howmuch);
+	if (__predict_false(rv != 0)) {
+		if (rv == EINVAL) {
+			printf("rumpuser_malloc: invalid alignment %d\n",
+			    alignment);
+			abort();
+		}
+		mem = NULL;
+	}
 
 	return mem;
 }

Reply via email to