daemon: Remove ‘AutoDeleteArray’.

* libutil/util.hh (AutoDeleteArray): Remove.
* libutil/util.cc (readString, readStrings): Use ‘std::vector’ instead
of ‘AutoDeleteArray’.
* libutil/serialise.cc (readFile): Likewise.

Change-Id: I45362998dbb8226874f66b77cd19f071f7bb2ab3
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Congcong Kuo 2025-05-27 01:49:56 +08:00 committed by Ludovic Courtès
parent c29534228f
commit 583e0688e3
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
3 changed files with 12 additions and 26 deletions

View file

@ -251,11 +251,10 @@ size_t readString(unsigned char * buf, size_t max, Source & source)
string readString(Source & source) string readString(Source & source)
{ {
size_t len = readInt(source); size_t len = readInt(source);
unsigned char * buf = new unsigned char[len]; std::vector<unsigned char> buf(len);
AutoDeleteArray<unsigned char> d(buf); source(buf.data(), buf.size());
source(buf, len); readPadding(buf.size(), source);
readPadding(len, source); return string((char *) buf.data(), buf.size());
return string((char *) buf, len);
} }

View file

@ -271,11 +271,10 @@ string readFile(int fd)
if (fstat(fd, &st) == -1) if (fstat(fd, &st) == -1)
throw SysError("statting file"); throw SysError("statting file");
unsigned char * buf = new unsigned char[st.st_size]; std::vector<unsigned char> buf(st.st_size);
AutoDeleteArray<unsigned char> d(buf); readFull(fd, buf.data(), buf.size());
readFull(fd, buf, st.st_size);
return string((char *) buf, st.st_size); return string((char *) buf.data(), buf.size());
} }

View file

@ -194,18 +194,6 @@ string drainFD(int fd);
/* Automatic cleanup of resources. */ /* Automatic cleanup of resources. */
template <class T>
struct AutoDeleteArray
{
T * p;
AutoDeleteArray(T * p) : p(p) { }
~AutoDeleteArray()
{
delete [] p;
}
};
class AutoDelete class AutoDelete
{ {
Path path; Path path;