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/serialise.cc8
-rw-r--r--src/libutil/util.cc7
-rw-r--r--src/libutil/util.hh12
3 files changed, 7 insertions, 20 deletions
diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 24c6d107359e..a68f7a0fa8ee 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -3,6 +3,7 @@
 
 #include <cstring>
 #include <cerrno>
+#include <memory>
 
 
 namespace nix {
@@ -236,11 +237,10 @@ size_t readString(unsigned char * buf, size_t max, Source & source)
 string readString(Source & source)
 {
     size_t len = readInt(source);
-    unsigned char * buf = new unsigned char[len];
-    AutoDeleteArray<unsigned char> d(buf);
-    source(buf, len);
+    auto buf = std::make_unique<unsigned char[]>(len);
+    source(buf.get(), len);
     readPadding(len, source);
-    return string((char *) buf, len);
+    return string((char *) buf.get(), len);
 }
 
 Source & operator >> (Source & in, string & s)
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index ce16cc30a5c7..0e1849df09ea 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -272,11 +272,10 @@ string readFile(int fd)
     if (fstat(fd, &st) == -1)
         throw SysError("statting file");
 
-    unsigned char * buf = new unsigned char[st.st_size];
-    AutoDeleteArray<unsigned char> d(buf);
-    readFull(fd, buf, st.st_size);
+    auto buf = std::make_unique<unsigned char[]>(st.st_size);
+    readFull(fd, buf.get(), st.st_size);
 
-    return string((char *) buf, st.st_size);
+    return string((char *) buf.get(), st.st_size);
 }
 
 
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 50b96f7ed92c..d420997815f5 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -139,18 +139,6 @@ string drainFD(int fd);
 /* Automatic cleanup of resources. */
 
 
-template <class T>
-struct AutoDeleteArray
-{
-    T * p;
-    AutoDeleteArray(T * p) : p(p) { }
-    ~AutoDeleteArray()
-    {
-        delete [] p;
-    }
-};
-
-
 class AutoDelete
 {
     Path path;