diff options
author | Bernard Normier <bernard@zeroc.com> | 2016-06-21 12:01:31 -0400 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2016-06-21 12:01:31 -0400 |
commit | 6bc014bf8a0ee28909194328d25bbe9ce760d473 (patch) | |
tree | d7f2821a9aea3e6b50c475a7f633e5d705909297 /cpp/src | |
parent | Improved InputStream and OutputStream in C++11 (diff) | |
download | ice-6bc014bf8a0ee28909194328d25bbe9ce760d473.tar.bz2 ice-6bc014bf8a0ee28909194328d25bbe9ce760d473.tar.xz ice-6bc014bf8a0ee28909194328d25bbe9ce760d473.zip |
Replaced malloc/realloc by vector
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceGrid/ServerI.cpp | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp index df9f243d27d..404b1e77606 100644 --- a/cpp/src/IceGrid/ServerI.cpp +++ b/cpp/src/IceGrid/ServerI.cpp @@ -44,7 +44,7 @@ namespace IceGrid void chownRecursive(const string& path, uid_t uid, gid_t gid) { - struct dirent **namelist = 0; + vector<vector<Ice::Byte> > namelist; DIR* d; if((d = opendir(path.c_str())) == 0) { @@ -52,26 +52,15 @@ chownRecursive(const string& path, uid_t uid, gid_t gid) } struct dirent* entry; - int n = 0; while((entry = readdir(d)) != 0) { - namelist = static_cast<struct dirent**>( - realloc(namelist, static_cast<size_t>((n + 1) * sizeof(struct dirent*)))); - if(namelist == 0) - { - closedir(d); - throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString(); - } + size_t index = namelist.size(); + namelist.resize(index + 1); size_t entrysize = sizeof(struct dirent) - sizeof(entry->d_name) + strlen(entry->d_name) + 1; - namelist[n] = static_cast<struct dirent*>(malloc(entrysize)); - if(namelist[n] == 0) - { - closedir(d); - throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString(); - } - memcpy(namelist[n], entry, entrysize); - ++n; + namelist[index].resize(entrysize); + + memcpy(&namelist[index][0], entry, entrysize); } if(closedir(d)) @@ -79,11 +68,10 @@ chownRecursive(const string& path, uid_t uid, gid_t gid) throw "cannot read directory `" + path + "':\n" + IceUtilInternal::lastErrorToString(); } - for(int i = 0; i < n; ++i) + for(size_t i = 0; i < namelist.size(); ++i) { - string name = namelist[i]->d_name; + string name = reinterpret_cast<struct dirent*>(&namelist[i][0])->d_name; assert(!name.empty()); - free(namelist[i]); if(name == ".") { @@ -115,8 +103,6 @@ chownRecursive(const string& path, uid_t uid, gid_t gid) } } } - - free(namelist); } #endif |