about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-10-28T12·29+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-10-28T12·29+0000
commite11e6fb1c6709ca3f0e596a7b1fb988df2fbd9b1 (patch)
treeb77c8230ccc77327f2feae591c2e0932610d9bb0 /src/libexpr
parent8a788e38ac7efc785ffe4fcf49a4e031c7784216 (diff)
* Handle out of memory condition.
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/eval.cc10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 919ebd4ba9b6..c36a679d350d 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -259,9 +259,8 @@ void mkString(Value & v, const string & s, const PathSet & context)
     mkString(v, s.c_str());
     if (!context.empty()) {
         unsigned int n = 0;
-        v.string.context = (const char * *)
-            GC_MALLOC((context.size() + 1) * sizeof(char *));
-        foreach (PathSet::const_iterator, i, context) 
+        v.string.context = NEW const char *[context.size() + 1];
+        foreach (PathSet::const_iterator, i, context)  
             v.string.context[n++] = GC_STRDUP(i->c_str());
         v.string.context[n] = 0;
     }
@@ -305,7 +304,7 @@ Value * EvalState::lookupVar(Env * env, const VarRef & var)
 Value * EvalState::allocValue()
 {
     nrValues++;
-    return (Value *) GC_MALLOC(sizeof(Value));
+    return NEW Value;
 }
 
 
@@ -314,6 +313,7 @@ Env & EvalState::allocEnv(unsigned int size)
     nrEnvs++;
     nrValuesInEnvs += size;
     Env * env = (Env *) GC_MALLOC(sizeof(Env) + size * sizeof(Value *));
+    if (!env) throw std::bad_alloc();
 
     /* Clear the values because maybeThunk() expects this. */
     for (unsigned i = 0; i < size; ++i)
@@ -335,7 +335,7 @@ void EvalState::mkList(Value & v, unsigned int length)
 {
     v.type = tList;
     v.list.length = length;
-    v.list.elems = (Value * *) GC_MALLOC(length * sizeof(Value *));
+    v.list.elems = NEW Value *[length];
     nrListElems += length;
 }