Bugzilla bug 226356: test for NULL before dereferencing a pointer. The
authorwchang0222%aol.com
Sat, 22 Nov 2003 06:57:02 +0000
changeset 2977 d25afe6eca866b7366dd8c94bd440c94c00789dd
parent 2976 407802ff94b4c5646bbf5facb229ec6b170ec51e
child 2978 a1eceb0a5afcc1b9f4279200a45be3b634dd6308
push idunknown
push userunknown
push dateunknown
bugs226356
Bugzilla bug 226356: test for NULL before dereferencing a pointer. The patch is contributed by timeless@bemail.org. r=wtc. Modified Files: bthreads/btmon.c pthreads/ptsynch.c threads/prmon.c
pr/src/bthreads/btmon.c
pr/src/pthreads/ptsynch.c
pr/src/threads/prmon.c
--- a/pr/src/bthreads/btmon.c
+++ b/pr/src/bthreads/btmon.c
@@ -73,17 +73,20 @@ PR_IMPLEMENT(PRMonitor*)
     }
 
     return( mon );
 }
 
 PR_IMPLEMENT(PRMonitor*) PR_NewNamedMonitor(const char* name)
 {
     PRMonitor* mon = PR_NewMonitor();
-    mon->name = name;
+    if( mon )
+    {
+        mon->name = name;
+    }
     return mon;
 }
 
 /*
 ** Destroy a monitor. The caller is responsible for guaranteeing that the
 ** monitor is no longer in use. There must be no thread waiting on the
 ** monitor's condition variable and that the lock is not held.
 **
--- a/pr/src/pthreads/ptsynch.c
+++ b/pr/src/pthreads/ptsynch.c
@@ -466,17 +466,18 @@ PR_IMPLEMENT(PRMonitor*) PR_NewMonitor(v
         }
     }
     return mon;
 }  /* PR_NewMonitor */
 
 PR_IMPLEMENT(PRMonitor*) PR_NewNamedMonitor(const char* name)
 {
     PRMonitor* mon = PR_NewMonitor();
-    mon->name = name;
+    if (mon)
+        mon->name = name;
     return mon;
 }
 
 PR_IMPLEMENT(void) PR_DestroyMonitor(PRMonitor *mon)
 {
     int rv;
     PR_ASSERT(mon != NULL);
     PR_DestroyCondVar(mon->cvar);
--- a/pr/src/threads/prmon.c
+++ b/pr/src/threads/prmon.c
@@ -63,17 +63,18 @@ PR_IMPLEMENT(PRMonitor*) PR_NewMonitor()
 	mon->name = NULL;
     }
     return mon;
 }
 
 PR_IMPLEMENT(PRMonitor*) PR_NewNamedMonitor(const char* name)
 {
     PRMonitor* mon = PR_NewMonitor();
-    mon->name = name;
+    if (mon)
+        mon->name = name;
     return mon;
 }
 
 /*
 ** Destroy a monitor. There must be no thread waiting on the monitor's
 ** condition variable. The caller is responsible for guaranteeing that the
 ** monitor is no longer in use.
 */