about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index de2dd12ad42e..38e32bfa9b58 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -194,12 +194,26 @@ Strings readDirectory(const Path & path)
 }
 
 
+template <class T>
+struct AutoDeleteArray
+{
+    T * p;
+    AutoDeleteArray(T * p) : p(p) { }
+    ~AutoDeleteArray() 
+    {
+        delete [] p;
+    }
+};
+
+
 string readFile(int fd)
 {
     struct stat st;
     if (fstat(fd, &st) == -1)
         throw SysError("statting file");
-    unsigned char buf[st.st_size]; /* !!! stack space */
+    
+    unsigned char * buf = new unsigned char[st.st_size];
+    AutoDeleteArray<unsigned char> d(buf);
     readFull(fd, buf, st.st_size);
 
     return string((char *) buf, st.st_size);