summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2008-05-09 13:41:22 +0200
committerBenoit Foucher <benoit@zeroc.com>2008-05-09 13:41:22 +0200
commit234203502ea515f475a747c5fdeccb054195b195 (patch)
tree2d859f53f3ddbd2c0a42f344db9586b2a21e13f7 /cpp/src
parenthttp://bugzilla/bugzilla/show_bug.cgi?id=3120 - updated demo/IceStorm/replica... (diff)
downloadice-234203502ea515f475a747c5fdeccb054195b195.tar.bz2
ice-234203502ea515f475a747c5fdeccb054195b195.tar.xz
ice-234203502ea515f475a747c5fdeccb054195b195.zip
Fixed bug 3128 & 3129 - icepatch2server crash on exit bug
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Service.cpp4
-rw-r--r--cpp/src/IceGrid/Activator.cpp11
-rw-r--r--cpp/src/IceUtil/ArgVector.cpp119
3 files changed, 24 insertions, 110 deletions
diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp
index af3838b2b5c..c8145f93fd7 100644
--- a/cpp/src/Ice/Service.cpp
+++ b/cpp/src/Ice/Service.cpp
@@ -709,9 +709,7 @@ int
Ice::Service::main(StringSeq& args, const InitializationData& initData)
{
IceUtilInternal::ArgVector av(args);
- int rc = main(av.argc, av.argv, initData);
- argsToStringSeq(av.argc, av.argv);
- return rc;
+ return main(av.argc, av.argv, initData);
}
Ice::CommunicatorPtr
diff --git a/cpp/src/IceGrid/Activator.cpp b/cpp/src/IceGrid/Activator.cpp
index 1ce7135e15b..501f8110741 100644
--- a/cpp/src/IceGrid/Activator.cpp
+++ b/cpp/src/IceGrid/Activator.cpp
@@ -682,15 +682,14 @@ Activator::activate(const string& name,
for(int i = 0; i < env.argc; i++)
{
- if(putenv(env.argv[i]) != 0)
+ //
+ // Each env is leaked on purpose ... see man putenv().
+ //
+ if(putenv(strdup(env.argv[i])) != 0)
{
reportChildError(errno, fds[1], "cannot set environment variable", env.argv[i]);
}
}
- //
- // Each env is leaked on purpose ... see man putenv().
- //
- env.setNoDelete();
//
// Change working directory.
@@ -701,7 +700,7 @@ Activator::activate(const string& name,
{
reportChildError(errno, fds[1], "cannot change working directory to", pwdCStr);
}
- }
+ }
if(execvp(av.argv[0], av.argv) == -1)
{
diff --git a/cpp/src/IceUtil/ArgVector.cpp b/cpp/src/IceUtil/ArgVector.cpp
index a9f01088b6e..4f7dc1bc910 100644
--- a/cpp/src/IceUtil/ArgVector.cpp
+++ b/cpp/src/IceUtil/ArgVector.cpp
@@ -14,135 +14,52 @@
IceUtilInternal::ArgVector::ArgVector(int argc, char *argv[])
{
assert(argc >= 0);
- _noDelete = false;
- copyVec(argc, argc, argv);
+ _args.resize(argc);
+ for(int i = 0; i < argc; ++i)
+ {
+ _args[i] = argv[i];
+ }
+ setupArgcArgv();
}
IceUtilInternal::ArgVector::ArgVector(const ::std::vector< ::std::string>& vec)
{
- _noDelete = false;
- copyVec(vec);
+ _args = vec;
+ setupArgcArgv();
}
IceUtilInternal::ArgVector::ArgVector(const ArgVector& rhs)
{
- _noDelete = false;
- copyVec(rhs.argc, rhs._origArgc, rhs.argv);
+ _args = rhs._args;
+ setupArgcArgv();
}
IceUtilInternal::ArgVector&
IceUtilInternal::ArgVector::operator=(const ArgVector& rhs)
{
- ArgVector tmp(rhs);
- swap(tmp);
+ delete[] argv;
+ argv = 0;
+ _args = rhs._args;
+ setupArgcArgv();
return *this;
}
IceUtilInternal::ArgVector::~ArgVector()
{
- //
- // For use with putenv()--see man putenv.
- //
- if(!_noDelete)
- {
- for(int i = 0; i < _origArgc; ++i)
- {
- delete[] argv[i];
- }
- }
delete[] argv;
}
void
-IceUtilInternal::ArgVector::setNoDelete()
+IceUtilInternal::ArgVector::setupArgcArgv()
{
- _noDelete = true;
-}
-
-void
-IceUtilInternal::ArgVector::copyVec(int argc, int origArgc, char** argv)
-{
- this->argc = argc;
- this->_origArgc = origArgc;
- if((this->argv = new char*[argc + 1]) == 0)
- {
- throw ::std::bad_alloc();
- }
- for(int i = 0; i < argc; ++i)
- {
- try
- {
- if((this->argv[i] = new char[strlen(argv[i]) + 1]) == 0)
- {
- throw ::std::bad_alloc();
- }
- }
- catch(...)
- {
- for(int j = 0; j < i; ++j)
- {
- delete[] this->argv[j];
- }
- delete[] this->argv;
- throw;
- }
-#if defined(_MSC_VER) && (_MSC_VER >= 1400)
- strcpy_s(this->argv[i], strlen(argv[i]) + 1, argv[i]);
-#else
- strcpy(this->argv[i], argv[i]);
-#endif
- }
- this->argv[argc] = 0;
-}
-
-void
-IceUtilInternal::ArgVector::copyVec(const ::std::vector< ::std::string>& vec)
-{
- argc = _origArgc = static_cast<int>(vec.size());
+ argc = _args.size();
if((argv = new char*[argc + 1]) == 0)
{
throw ::std::bad_alloc();
}
- for(int i = 0; i < argc; ++i)
+ for(int i = 0; i < argc; i++)
{
- try
- {
- if((argv[i] = new char[vec[i].size() + 1]) == 0)
- {
- throw ::std::bad_alloc();
- }
- }
- catch(...)
- {
- for(int j = 0; j < i; ++j)
- {
- delete[] argv[j];
- }
- delete[] argv;
- throw;
- }
-#if defined(_MSC_VER) && (_MSC_VER >= 1400)
- strcpy_s(argv[i], vec[i].size() + 1, vec[i].c_str());
-#else
- strcpy(argv[i], vec[i].c_str());
-#endif
+ argv[i] = const_cast<char*>(_args[i].c_str());
}
argv[argc] = 0;
}
-
-void
-IceUtilInternal::ArgVector::swap(ArgVector& rhs) throw()
-{
- int argcTmp = rhs.argc;
- int origArgcTmp = rhs._origArgc;
- char** argvTmp = rhs.argv;
- bool noDeleteTmp = rhs._noDelete;
- rhs.argc = argc;
- rhs._origArgc = _origArgc;
- rhs.argv = argv;
- rhs._noDelete = _noDelete;
- argc = argcTmp;
- _origArgc = origArgcTmp;
- argv = argvTmp;
- _noDelete = noDeleteTmp;
-}