diff mbox

[09/12] xf86drmSL: Check memory allocation by SL_RANDOM_INIT()

Message ID 1427963547-23614-10-git-send-email-praveen.paneri@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Praveen Paneri April 2, 2015, 8:32 a.m. UTC
If the allocation fails, return -ENOMEM. Handle the return value
at the caller funtion drmSLInsert() as well.

Signed-off-by: Praveen Paneri <praveen.paneri@intel.com>
---
 xf86drmSL.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox

Patch

diff --git a/xf86drmSL.c b/xf86drmSL.c
index 45f3906..edafe7b 100644
--- a/xf86drmSL.c
+++ b/xf86drmSL.c
@@ -40,6 +40,7 @@ 
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #define SL_MAIN 0
 
@@ -124,6 +125,7 @@  static int SLRandomLevel(void)
     SL_RANDOM_DECL;
 
     SL_RANDOM_INIT(SL_RANDOM_SEED);
+    if (!state) return -ENOMEM;
     
     while ((SL_RANDOM & 0x01) && level < SL_MAX_LEVEL) ++level;
     return level;
@@ -200,6 +202,9 @@  int drmSLInsert(void *l, unsigned long key, void *value)
 
 
     level = SLRandomLevel();
+    if (level < 0)
+	return level;
+
     if (level > list->level) {
 	level = ++list->level;
 	update[level] = list->head;