diff --git a/net/auth/src/TAuthenticate.cxx b/net/auth/src/TAuthenticate.cxx index 0354ec190b7a866181fc5fd8bece981fa63785ab..7d2d0ca4f0bd18938939093c319944cd5955ae9d 100644 --- a/net/auth/src/TAuthenticate.cxx +++ b/net/auth/src/TAuthenticate.cxx @@ -502,8 +502,11 @@ negotia: if (user != "") CheckNetrc(user, passwd, pwhash, kTRUE); if (passwd == "") { - if (fgPromptUser) - user = PromptUser(fRemote); + if (fgPromptUser) { + char *p = PromptUser(fRemote); + user = p; + delete [] p; + } rc = GetUserPasswd(user, passwd, pwhash, kTRUE); } fUser = user; diff --git a/net/rootd/src/rootd.cxx b/net/rootd/src/rootd.cxx index 77218ce055d5b018866f82ba3d87637d780de064..908617ddc2a814f6a1c54d669f1d35d2fc95c0c5 100644 --- a/net/rootd/src/rootd.cxx +++ b/net/rootd/src/rootd.cxx @@ -745,6 +745,7 @@ again: // lock the file if (lockf(fid, F_LOCK, (off_t)1) == -1) { ErrorInfo("RootdCloseTab: error locking %s", sfile); + close(fid); return; } if (gDebug > 2) @@ -814,6 +815,7 @@ again: lseek(fid, 0, SEEK_SET); if (lockf(fid, F_ULOCK, (off_t)1) == -1) { ErrorInfo("RootdCloseTab: error unlocking %s", sfile); + close(fid); return; } if (gDebug > 2) diff --git a/net/rpdutils/src/rpdutils.cxx b/net/rpdutils/src/rpdutils.cxx index 222172dadc118dba9b72312c4b1b31658bfdc7f4..463c572edfb484b43e9ea709f4cb2afc8d5818d1 100644 --- a/net/rpdutils/src/rpdutils.cxx +++ b/net/rpdutils/src/rpdutils.cxx @@ -944,7 +944,7 @@ int RpdUpdateAuthTab(int opt, const char *line, char **token, int ilck) } goingout: - if (ilck == 0) { + if (itab != ilck) { // unlock the file lseek(itab, 0, SEEK_SET); if (lockf(itab, F_ULOCK, (off_t) 1) == -1) { @@ -2450,6 +2450,7 @@ int RpdSshAuth(const char *sstr) NetSend(kErrNoPipeInfo, kROOTD_ERR); delete[] uniquePipe; delete[] pipeFile; + close(unixFd); return auth; } else { // File open: fill it @@ -4516,14 +4517,17 @@ int RpdCheckSshd(int opt) localAddr.sin_port = htons(0); if (bind(sd, (struct sockaddr *) &localAddr, sizeof(localAddr)) < 0) { ErrorInfo("RpdCheckSshd: cannot bind to local port %u", gSshdPort); + close(sd); return 0; } // connect to server if (connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0) { ErrorInfo("RpdCheckSshd: cannot connect to local port %u", gSshdPort); + close(sd); return 0; } + close(sd); // Sshd successfully contacted if (gDebug > 2) ErrorInfo("RpdCheckSshd: success!"); @@ -6634,6 +6638,7 @@ int RpdRetrieveSpecialPass(const char *usr, const char *fpw, char *pass, int lpw if (fstat(fid, &st) == -1) { ErrorInfo("RpdRetrieveSpecialPass: cannot stat descriptor %d" " %s (errno: %d)", fid, GetErrno()); + close(fid); rc = -1; goto back; } @@ -6643,6 +6648,7 @@ int RpdRetrieveSpecialPass(const char *usr, const char *fpw, char *pass, int lpw " 0%o (should be 0600)", rootdpass, (st.st_mode & 0777)); ErrorInfo("RpdRetrieveSpecialPass: %d %d", S_ISREG(st.st_mode),S_ISDIR(st.st_mode)); + close(fid); rc = -2; goto back; } diff --git a/net/rpdutils/src/ssh.cxx b/net/rpdutils/src/ssh.cxx index 5b7b2485d4f57f0982134ac5d5f718fb645b9e51..9967212bc678c0dc4572b3610c15501ef08a0aba 100644 --- a/net/rpdutils/src/ssh.cxx +++ b/net/rpdutils/src/ssh.cxx @@ -227,6 +227,7 @@ int SshToolNotifyFailure(const char *Pipe) connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr))) < 0) { ErrorInfo("SshToolNotifyFailure: cannot connect socket: exiting "); + close(sd); return 1; } // Sending "KO" ... @@ -237,6 +238,7 @@ int SshToolNotifyFailure(const char *Pipe) ("SshToolNotifyFailure: sending might have been unsuccessful (bytes send: %d)", rc); } + close(sd); return 0; } diff --git a/proof/proofd/src/XrdProofConn.cxx b/proof/proofd/src/XrdProofConn.cxx index 56e587e1e0b9bfe36e8ea8df2d92975df98218ab..d518ea3b3568363a3dcfa8aab1f2682bd2108f03 100644 --- a/proof/proofd/src/XrdProofConn.cxx +++ b/proof/proofd/src/XrdProofConn.cxx @@ -27,6 +27,7 @@ #include "XpdSysPthread.h" #include "XrdProofConn.h" +#include "XrdProofdAux.h" #include "XProofProtocol.h" #include "XrdClient/XrdClientConnMgr.hh" @@ -85,9 +86,6 @@ int XrdProofConn::fgTimeWait = 2; // seconds XrdSysPlugin *XrdProofConn::fgSecPlugin = 0; // Sec library plugin void *XrdProofConn::fgSecGetProtocol = 0; // Sec protocol getter -#ifndef SafeDelete -#define SafeDelete(x) { if (x) { delete x; x = 0; } } -#endif #define URLTAG "["<<fUrl.Host<<":"<<fUrl.Port<<"]" //_____________________________________________________________________________ @@ -297,8 +295,8 @@ XrdProofConn::~XrdProofConn() } // Cleanup mutex - SafeDelete(fMutex); - SafeDelete(fConnectInterruptMtx); + SafeDel(fMutex); + SafeDel(fConnectInterruptMtx); } //_____________________________________________________________________________ @@ -553,7 +551,7 @@ XrdClientMessage *XrdProofConn::SendRecv(XPClientRequest *req, const void *reqDa TRACE(XERR, "reallocating "<<dataRecvSize<<" bytes"); free((void *) *answData); *answData = 0; - SafeDelete(xmsg); + SafeDel(xmsg); return xmsg; } } @@ -581,7 +579,7 @@ XrdClientMessage *XrdProofConn::SendRecv(XPClientRequest *req, const void *reqDa XPD::convertRespStatusToChar(xmsg->fHdr.status)<< "] (server "<<URLTAG<<") - Abort"); // We cannot continue - SafeDelete(xmsg); + SafeDel(xmsg); return xmsg; } // The last message may be empty: not an error @@ -672,7 +670,7 @@ XrdClientMessage *XrdProofConn::SendReq(XPClientRequest *req, const void *reqDat } if (abortcmd) { // Cleanup if failed - SafeDelete(answMex); + SafeDel(answMex); } else if (!resp) { // Sleep a while before retrying int sleeptime = 1; @@ -1190,7 +1188,7 @@ bool XrdProofConn::Login() notdone = 0; } // Cleanup - SafeDelete(xrsp); + SafeDel(xrsp); } else { // We failed but we are done with this attempt resp = 0; @@ -1320,7 +1318,7 @@ XrdSecProtocol *XrdProofConn::Authenticate(char *plist, int plsiz) reqhdr.header.dlen = (credentials) ? credentials->size : 0; char *credbuf = (credentials) ? credentials->buffer : 0; xrsp = SendReq(&reqhdr, credbuf, &srvans, "XrdProofConn::Authenticate"); - SafeDelete(credentials); + SafeDel(credentials); status = (xrsp) ? xrsp->HeaderStatus() : kXR_error; dlen = (xrsp) ? xrsp->DataLen() : 0; TRACE(HDBG, "server reply: status: "<<status<<" dlen: "<<dlen); @@ -1334,7 +1332,7 @@ XrdSecProtocol *XrdProofConn::Authenticate(char *plist, int plsiz) // // then get next part of the credentials credentials = protocol->getCredentials(secToken, &ei); - SafeDelete(secToken); // nb: srvans is released here + SafeDel(secToken); // nb: srvans is released here srvans = 0; if (!credentials) { TRACE(XERR, "cannot obtain credentials"); @@ -1348,7 +1346,7 @@ XrdSecProtocol *XrdProofConn::Authenticate(char *plist, int plsiz) // Server does not implement yet full cycling, so we are // allowed to try the handshake only for one protocol; we // cleanup the message and fail; - SafeDelete(xrsp); + SafeDel(xrsp); failed = 1; break; } else { @@ -1364,7 +1362,7 @@ XrdSecProtocol *XrdProofConn::Authenticate(char *plist, int plsiz) } } // Cleanup message - SafeDelete(xrsp); + SafeDel(xrsp); } // If we are done diff --git a/proof/proofd/src/XrdProofSched.cxx b/proof/proofd/src/XrdProofSched.cxx index ef1e2315f70ec8e7e887841e3a5bf74f3c7e1a37..03b996643ba0c2ca54ccaa8f7b0d69b73d93c788 100644 --- a/proof/proofd/src/XrdProofSched.cxx +++ b/proof/proofd/src/XrdProofSched.cxx @@ -540,11 +540,11 @@ int XrdProofSched::GetWorkers(XrdProofdProofServ *xps, if (TRACING(REQ)) xps->DumpQueries(); // Notify enqueing TRACE(REQ, "no workers currently available: session enqueued"); - SafeDelete(acwseff); + SafeDel(acwseff); return 2; } else { TRACE(XERR, "no worker available: do nothing"); - SafeDelete(acwseff); + SafeDel(acwseff); return -1; } } @@ -552,7 +552,7 @@ int XrdProofSched::GetWorkers(XrdProofdProofServ *xps, // If the session has already assigned workers just return if (xps->Workers()->Num() > 0) { // Current assignement is valid - SafeDelete(acwseff); + SafeDel(acwseff); return 1; } diff --git a/proof/proofd/src/XrdProofWorker.cxx b/proof/proofd/src/XrdProofWorker.cxx index 90b750d2b67f9b2fbe90cd220560a058557991df..ef00e908905396425f2f3690dd58fcc191d15eff 100644 --- a/proof/proofd/src/XrdProofWorker.cxx +++ b/proof/proofd/src/XrdProofWorker.cxx @@ -53,7 +53,7 @@ XrdProofWorker::~XrdProofWorker() { // Destructor - SafeDelete(fMutex); + SafeDel(fMutex); } //______________________________________________________________________________ diff --git a/proof/proofd/src/XrdProofdAdmin.cxx b/proof/proofd/src/XrdProofdAdmin.cxx index 31f23d7cfa56bc454d6d138014085dfdfbdaac0d..90c20d8670bd258f6f47e5c0f9d1f8e86ed6064b 100644 --- a/proof/proofd/src/XrdProofdAdmin.cxx +++ b/proof/proofd/src/XrdProofdAdmin.cxx @@ -1254,7 +1254,7 @@ int XrdProofdAdmin::Exec(XrdProofdProtocol *p) } } // Cleanup answer - SafeDelete(xrsp); + SafeDel(xrsp); } } @@ -1830,49 +1830,50 @@ int XrdProofdAdmin::GetFile(XrdProofdProtocol *p) snprintf(sizmsg, 64, "%lld", (kXR_int64) st.st_size); response->Send((const char *) &sizmsg[0]); TRACEP(p, XERR, "size is "<<sizmsg<<" bytes"); - } - // Now we send the content - const int kMAXBUF = 16384; - char buf[kMAXBUF]; - off_t pos = 0; - lseek(fd, pos, SEEK_SET); - - while (rc == 0 && pos < st.st_size) { - off_t left = st.st_size - pos; - if (left > kMAXBUF) left = kMAXBUF; - - int siz; - while ((siz = read(fd, &buf[0], left)) < 0 && errno == EINTR) - errno = 0; - if (siz < 0 || siz != left) { - emsg = "error reading from file: errno: "; - emsg += (int) errno; - rc = 1; - break; - } - int src = 0; - if ((src = response->Send(kXR_attn, kXPD_msg, (void *)&buf[0], left)) != 0) { - emsg = "error reading from file: errno: "; - emsg += src; - rc = 1; - break; + // Now we send the content + const int kMAXBUF = 16384; + char buf[kMAXBUF]; + off_t pos = 0; + lseek(fd, pos, SEEK_SET); + + while (rc == 0 && pos < st.st_size) { + off_t left = st.st_size - pos; + if (left > kMAXBUF) left = kMAXBUF; + + int siz; + while ((siz = read(fd, &buf[0], left)) < 0 && errno == EINTR) + errno = 0; + if (siz < 0 || siz != left) { + emsg = "error reading from file: errno: "; + emsg += (int) errno; + rc = 1; + break; + } + + int src = 0; + if ((src = response->Send(kXR_attn, kXPD_msg, (void *)&buf[0], left)) != 0) { + emsg = "error reading from file: errno: "; + emsg += src; + rc = 1; + break; + } + // Re-position + pos += left; + // Reset the timeout + if (pp.Post(0, "") != 0) { + rc = 1; + break; + } } - // Re-position - pos += left; - // Reset the timeout - if (pp.Post(0, "") != 0) { - rc = 1; - break; + // Close the file + close(fd); + // Send error, if any + if (rc != 0) { + TRACEP(p, XERR, emsg); + response->Send(kXR_attn, kXPD_srvmsg, 0, (char *) emsg.c_str(), emsg.length()); } } - // Close the file - close(fd); - // Send error, if any - if (rc != 0) { - TRACEP(p, XERR, emsg); - response->Send(kXR_attn, kXPD_srvmsg, 0, (char *) emsg.c_str(), emsg.length()); - } } // Send error, if any diff --git a/proof/proofd/src/XrdProofdAux.cxx b/proof/proofd/src/XrdProofdAux.cxx index 72501d84e1598337ea9ddc34614bb30ff2aeb4f6..198d92177b514241fd657483c04d3390a701119c 100644 --- a/proof/proofd/src/XrdProofdAux.cxx +++ b/proof/proofd/src/XrdProofdAux.cxx @@ -1523,7 +1523,7 @@ int XrdProofdAux::ReadMsg(int fd, XrdOucString &msg) msg += buf; } // Update counters - len -= nr; + len = (nr >= len) ? 0 : len - nr; } while (nr > 0 && len > 0); TRACE(HDBG,fd<<": buf: "<<buf); diff --git a/proof/proofd/src/XrdProofdClientMgr.cxx b/proof/proofd/src/XrdProofdClientMgr.cxx index 28ee8dd3927f1e7dcb0a4c669ef41cd88ba35f42..f1605d9406da16e4f2b7118cec19b05b6beb8b0d 100644 --- a/proof/proofd/src/XrdProofdClientMgr.cxx +++ b/proof/proofd/src/XrdProofdClientMgr.cxx @@ -632,7 +632,7 @@ int XrdProofdClientMgr::MapClient(XrdProofdProtocol *p, bool all) XrdSysMutexHelper mh(fMutex); fProofdClients.remove(pc); } - SafeDelete(pc); + SafeDel(pc); p->SetClient(0); } TRACEP(p, DBG, "cannot find valid instance of XrdProofdClient"); @@ -720,7 +720,7 @@ int XrdProofdClientMgr::MapClient(XrdProofdProtocol *p, bool all) if (CreateAdminPath(p, cpath, msg) != 0) { TRACEP(p, XERR, msg.c_str()); fProofdClients.remove(pc); - SafeDelete(pc); + SafeDel(pc); p->SetClient(0); response->Send(kXP_ServerError, msg.c_str()); return 0; @@ -1338,7 +1338,7 @@ char *XrdProofdClientMgr::FilterSecConfig(int &nd) // Close files fclose(fin); - close(fd); + if (fd >= 0) close(fd); return rcfn; } @@ -1403,7 +1403,7 @@ XrdProofdClient *XrdProofdClientMgr::GetClient(const char *usr, const char *grp, } } if (freeclient) { - SafeDelete(c); + SafeDel(c); } else if (TRACING(DBG)) { XPDFORM(dmsg, "instance for {client, group} = {%s, %s} created" " and added to the list (%p)", usr, grp, c); @@ -1412,7 +1412,7 @@ XrdProofdClient *XrdProofdClientMgr::GetClient(const char *usr, const char *grp, if (TRACING(XERR)) { XPDFORM(dmsg, "instance for {client, group} = {%s, %s} is invalid", usr, grp); } - SafeDelete(c); + SafeDel(c); } } else { if (TRACING(XERR)) { diff --git a/proof/proofd/src/XrdProofdLauncher.cxx b/proof/proofd/src/XrdProofdLauncher.cxx index 2c8f0d7e73aca9730fbc6c6470f9d87ec34fcc56..9399634831c7bb7d7c8e3debf417519decc1937d 100644 --- a/proof/proofd/src/XrdProofdLauncher.cxx +++ b/proof/proofd/src/XrdProofdLauncher.cxx @@ -78,7 +78,7 @@ XrdNetPeer *XrdProofdLauncher::Launch(ProofdLaunch_t *in, int &pid) xps->UNIXSockPath(), (int)errno); TRACE(XERR, emsg); XrdProofdAux::LogEmsgToFile(in->fErrLog.c_str(), emsg.c_str(), npfx.c_str()); - SafeDelete(unixsrv); + SafeDel(unixsrv); return peer; } @@ -93,7 +93,7 @@ XrdNetPeer *XrdProofdLauncher::Launch(ProofdLaunch_t *in, int &pid) XPDFORM(emsg, "failure from 'system' (errno: %d)", (int)errno); TRACE(XERR, emsg); XrdProofdAux::LogEmsgToFile(in->fErrLog.c_str(), emsg.c_str(), npfx.c_str()); - SafeDelete(unixsrv); + SafeDel(unixsrv); return peer; } @@ -105,10 +105,10 @@ XrdNetPeer *XrdProofdLauncher::Launch(ProofdLaunch_t *in, int &pid) XPDFORM(emsg, "failure accepting callback (errno: %d)", -err); TRACE(XERR, emsg); XrdProofdAux::LogEmsgToFile(in->fErrLog.c_str(), emsg.c_str(), npfx.c_str()); - SafeDelete(uconn); + SafeDel(uconn); return peer; } - SafeDelete(unixsrv); + SafeDel(unixsrv); TRACE(ALL, "proofserv connected!"); // diff --git a/proof/proofd/src/XrdProofdManager.cxx b/proof/proofd/src/XrdProofdManager.cxx index 51963e892fd7f5ba02996dc059b9085fbecc4c4d..f48fc958601ca7be742c5545a4b691eb9d0057da 100644 --- a/proof/proofd/src/XrdProofdManager.cxx +++ b/proof/proofd/src/XrdProofdManager.cxx @@ -205,13 +205,13 @@ XrdProofdManager::~XrdProofdManager() // Destructor // Destroy the configuration handler - SafeDelete(fAdmin); - SafeDelete(fClientMgr); - SafeDelete(fNetMgr); - SafeDelete(fPriorityMgr); - SafeDelete(fProofSched); - SafeDelete(fROOTMgr); - SafeDelete(fSessionMgr); + SafeDel(fAdmin); + SafeDel(fClientMgr); + SafeDel(fNetMgr); + SafeDel(fPriorityMgr); + SafeDel(fProofSched); + SafeDel(fROOTMgr); + SafeDel(fSessionMgr); SafeDelArray(fRootdArgsPtrs); } @@ -1129,6 +1129,7 @@ bool XrdProofdManager::ValidateLocalDataSetSrc(XrdOucString &url, bool &local) } else if (ofs != (off_t)(-1)) { TRACE(XERR, "Problems getting current position on file '" << fnpath << "'; errno: " << errno); } + fclose(flck); } } // Make sure that everybody can modify the file for updates @@ -1413,7 +1414,7 @@ int XrdProofdManager::DoDirectiveGroupfile(char *val, XrdOucStream *cfg, bool rc // Defines file with the group info if (rcf) { - SafeDelete(fGroupsMgr); + SafeDel(fGroupsMgr); } else if (fGroupsMgr) { TRACE(XERR, "groups manager already initialized: ignoring "); return -1; diff --git a/proof/proofd/src/XrdProofdNetMgr.cxx b/proof/proofd/src/XrdProofdNetMgr.cxx index 551893dae34c7e849891c9463002121ee37ce0be..028eb0408db2f690304cb802b9c6f8832e53e6c3 100644 --- a/proof/proofd/src/XrdProofdNetMgr.cxx +++ b/proof/proofd/src/XrdProofdNetMgr.cxx @@ -320,10 +320,10 @@ int XrdProofdNetMgr::DoDirectiveBonjour(char *val, XrdOucStream *cfg, bool) void XrdProofdNetMgr::BalanceNodesOrder() { // Indices (this will be used twice). - std::list<XrdProofWorker *>::const_iterator iter, iter2; - std::list<XrdProofWorker *>::iterator iter3; // Not const, less efficient. + list<XrdProofWorker *>::const_iterator iter, iter2; + list<XrdProofWorker *>::iterator iter3; // Not const, less efficient. // Map to store information of the balancer. - std::map<XrdProofWorker *, BalancerInfo> info; + map<XrdProofWorker *, BalancerInfo> info; // Node with minimum number of workers distinct to 1. unsigned int min = UINT_MAX; // Total number of nodes and per iteration assignments. @@ -331,7 +331,7 @@ void XrdProofdNetMgr::BalanceNodesOrder() // Number of iterations to get every node filled. unsigned int total_added = 0; // Temporary list to store the balanced configuration - std::list<XrdProofWorker *> tempNodes; + list<XrdProofWorker *> tempNodes; // Flag for the search and destroy loop. bool deleted; @@ -377,7 +377,7 @@ void XrdProofdNetMgr::BalanceNodesOrder() // Finally, do the round robin assignment of nodes. // Stop when every node has its workers processed. while (total_added < total) { - for (std::map<XrdProofWorker *, BalancerInfo>::iterator i = info.begin(); i != info.end(); i++) { + for (map<XrdProofWorker *, BalancerInfo>::iterator i = info.begin(); i != info.end(); i++) { if (i->second.added < i->second.available) { // Be careful with the remainders (on prime number of nodes). unsigned int to_add = xrdmin(i->second.per_iteration, @@ -1559,7 +1559,7 @@ char *XrdProofdNetMgr::ReadLogPaths(const char *url, const char *msg, int isess) reqhdr.proof.int1 = kQueryLogPaths; reqhdr.proof.int2 = isess; reqhdr.proof.sid = -1; - reqhdr.header.dlen = strlen(msg); + reqhdr.header.dlen = msg ? strlen(msg) : 0; const void *btmp = (const void *) msg; char **vout = &buf; // Send over diff --git a/proof/proofd/src/XrdProofdProofServ.cxx b/proof/proofd/src/XrdProofdProofServ.cxx index 3f4dbb0ec0204ca8574429acea2a46ce26f229a2..2d84ef9d22300bbe4370a9f161c46b1b97f63ca4 100644 --- a/proof/proofd/src/XrdProofdProofServ.cxx +++ b/proof/proofd/src/XrdProofdProofServ.cxx @@ -21,13 +21,6 @@ // Tracing utils #include "XrdProofdTrace.h" -#ifndef SafeDelete -#define SafeDelete(x) { if (x) { delete x; x = 0; } } -#endif -#ifndef SafeDelArray -#define SafeDelArray(x) { if (x) { delete[] x; x = 0; } } -#endif - //__________________________________________________________________________ XrdProofdProofServ::XrdProofdProofServ() { @@ -71,8 +64,8 @@ XrdProofdProofServ::~XrdProofdProofServ() { // Destructor - SafeDelete(fStartMsg); - SafeDelete(fPingSem); + SafeDel(fStartMsg); + SafeDel(fPingSem); std::vector<XrdClientID *>::iterator i; for (i = fClients.begin(); i != fClients.end(); i++) @@ -89,7 +82,7 @@ XrdProofdProofServ::~XrdProofdProofServ() // Remove the associated UNIX socket path unlink(fUNIXSockPath.c_str()); - SafeDelete(fMutex); + SafeDel(fMutex); } //__________________________________________________________________________ @@ -217,8 +210,8 @@ void XrdProofdProofServ::Reset() fResponse = 0; fProtocol = 0; fParent = 0; - SafeDelete(fStartMsg); - SafeDelete(fPingSem); + SafeDel(fStartMsg); + SafeDel(fPingSem); fSrvPID = -1; fID = -1; fIsShutdown = false; @@ -254,7 +247,7 @@ void XrdProofdProofServ::DeleteUNIXSock() { // Delete the current UNIX socket - SafeDelete(fUNIXSock); + SafeDel(fUNIXSock); unlink(fUNIXSockPath.c_str()); fUNIXSockPath = ""; } diff --git a/proof/proofd/src/XrdProofdProofServMgr.cxx b/proof/proofd/src/XrdProofdProofServMgr.cxx index 964340fa535263349f402daa8516aae69b8fbfa0..506c2a4e4556570cd243e9b8ade6bb52a6a486fa 100644 --- a/proof/proofd/src/XrdProofdProofServMgr.cxx +++ b/proof/proofd/src/XrdProofdProofServMgr.cxx @@ -442,8 +442,8 @@ int XrdProofdProofServMgr::AddSession(XrdProofdProtocol *p, XrdProofdProofServ * TRACE(REQ, "adding new active session ..."); // Check inputs - if (!s || !p || !p->Client()) { - TRACE(XERR,"invalid inputs: "<<p<<", "<<s<<", "<<p->Client()); + if (!s || !p->Client()) { + TRACE(XERR,"invalid inputs: "<<(s ? "" : "s, ") <<", "<< (p->Client() ? "" : "p->Client()")); return -1; } XrdProofdClient *c = p->Client(); @@ -470,7 +470,7 @@ bool XrdProofdProofServMgr::IsSessionSocket(const char *fpid) // Check inputs if (!fpid || strlen(fpid) <= 0) { - TRACE(XERR, "invalid input: "<<fpid); + TRACE(XERR, "invalid input: "<<(fpid ? fpid : "<nul>")); return 0; } @@ -508,7 +508,7 @@ int XrdProofdProofServMgr::MvSession(const char *fpid) // Check inputs if (!fpid || strlen(fpid) <= 0) { - TRACE(XERR, "invalid input: "<<fpid); + TRACE(XERR, "invalid input: "<<(fpid ? fpid : "<nul>")); return -1; } @@ -560,7 +560,7 @@ int XrdProofdProofServMgr::RmSession(const char *fpid) // Check inputs if (!fpid || strlen(fpid) <= 0) { - TRACE(XERR, "invalid input: "<<fpid); + TRACE(XERR, "invalid input: "<< (fpid ? fpid : "<nul>")); return -1; } @@ -583,11 +583,11 @@ int XrdProofdProofServMgr::TouchSession(const char *fpid, const char *fpath) // Update the access time for the session pid file to the current time XPDLOC(SMGR, "ProofServMgr::TouchSession") - TRACE(REQ, "touching "<<fpid<<", "<<fpath<<" ..."); + TRACE(REQ, "touching "<<(fpid ? fpid : "<nul>")<<", "<<(fpath ? fpath : "<nul>")<<" ..."); // Check inputs if (!fpid || strlen(fpid) <= 0) { - TRACE(XERR, "invalid input: "<<fpid); + TRACE(XERR, "invalid input: "<<(fpid ? fpid : "<nul>")); return -1; } @@ -617,7 +617,7 @@ int XrdProofdProofServMgr::VerifySession(const char *fpid, // Check inputs if (!fpid || strlen(fpid) <= 0) { - TRACE(XERR, "invalid input: "<<fpid); + TRACE(XERR, "invalid input: "<<(fpid ? fpid : "<nul>")); return -1; } @@ -675,7 +675,7 @@ int XrdProofdProofServMgr::DeleteFromSessions(const char *fpid) // Check inputs if (!fpid || strlen(fpid) <= 0) { - TRACE(XERR, "invalid input: "<<fpid); + TRACE(XERR, "invalid input: "<<(fpid ? fpid : "<nul>")); return -1; } @@ -861,7 +861,7 @@ bool XrdProofdProofServMgr::IsClientRecovering(const char *usr, const char *grp, XPDLOC(SMGR, "ProofServMgr::IsClientRecovering") if (!usr || !grp) { - TRACE(XERR, "invalid inputs: usr: "<<usr<<", grp:"<<grp<<" ..."); + TRACE(XERR, "invalid inputs: usr: "<<(usr ? usr : "")<<", grp:"<<(grp ? grp : "")<<" ..."); return false; } @@ -1905,8 +1905,16 @@ int XrdProofdProofServMgr::CreateFork(XrdProofdProtocol *p) char *argvv[6] = {0}; + // We set to the user environment + if (!fMgr) { + emsg = "XrdProofdManager instance undefined!"; + TRACE(XERR, emsg); + if (fcp.Post(0, emsg.c_str()) != 0) + TRACE(XERR, "cannot write to internal pipe; errno: "<<errno); + exit(1); + } char *sxpd = 0; - if (fMgr && fMgr->AdminPath()) { + if (fMgr->AdminPath()) { // We add our admin path to be able to identify processes coming from us size_t len = strlen(fMgr->AdminPath()) + strlen("xpdpath:") + 1; sxpd = new char[len]; @@ -2490,7 +2498,7 @@ int XrdProofdProofServMgr::Create(XrdProofdProtocol *p) emsg += errlog; emsg.insert(npfx, 0); response->Send(kXP_ServerError, emsg.c_str()); - SafeDelete(peersrv); + SafeDel(peersrv); return 0; } @@ -2533,10 +2541,10 @@ int XrdProofdProofServMgr::Create(XrdProofdProtocol *p) TRACEP(p, XERR, emsg.c_str()); emsg.insert(npfx, 0); response->Send(kXR_attn, kXPD_errmsg, (char *) emsg.c_str(), emsg.length()); - SafeDelete(peersrv); + SafeDel(peersrv); return 0; } - SafeDelete(peersrv); + SafeDel(peersrv); // Set the group, if any xps->SetGroup(p->Client()->Group()); @@ -2636,11 +2644,11 @@ int XrdProofdProofServMgr::ResolveSession(const char *fpid) // Handle a request to recover a session after stop&restart XPDLOC(SMGR, "ProofServMgr::ResolveSession") - TRACE(REQ, "resolving "<< fpid<<" ..."); + TRACE(REQ, "resolving "<< (fpid ? fpid : "<nul>")<<" ..."); // Check inputs if (!fpid || strlen(fpid)<= 0 || !(fMgr->ClientMgr()) || !fRecoverClients) { - TRACE(XERR, "invalid inputs: "<<fpid<<", "<<fMgr->ClientMgr()<< + TRACE(XERR, "invalid inputs: "<<(fpid ? fpid : "<nul>")<<", "<<fMgr->ClientMgr()<< ", "<<fRecoverClients); return -1; } @@ -4915,7 +4923,7 @@ int XrdProofSessionInfo::SaveToFile(const char *file) // Check inputs if (!file || strlen(file) <= 0) { - TRACE(XERR,"invalid input: "<<file); + TRACE(XERR,"invalid input: "<< (file ? file : "<nul>")); return -1; } @@ -4978,7 +4986,7 @@ int XrdProofSessionInfo::ReadFromFile(const char *file) // Check inputs if (!file || strlen(file) <= 0) { - TRACE(XERR,"invalid input: "<<file); + TRACE(XERR,"invalid input: "<<(file ? file : "<nul>")); return -1; } @@ -5052,7 +5060,7 @@ int XrdProofSessionInfo::ReadFromFile(const char *file) while ((len = read(fileno(fpid), line, wanted)) < 0 && errno == EINTR) errno = 0; - if (len < wanted) { + if (len < 0 || len < wanted) { break; } else { line[len] = '\0'; diff --git a/proof/proofd/src/XrdROOT.cxx b/proof/proofd/src/XrdROOT.cxx index 6adf7cd75ffe8e6da0a77e7835097574012cb007..323751ef312d81c470df71bc0b06897ce4950a02 100644 --- a/proof/proofd/src/XrdROOT.cxx +++ b/proof/proofd/src/XrdROOT.cxx @@ -444,7 +444,7 @@ int XrdROOTMgr::DoDirectiveRootSys(char *val, XrdOucStream *cfg, bool) if ((*ori)->Match(rootc->Dir(), rootc->Tag())) { if ((*ori)->IsParked()) { (*ori)->SetValid(); - SafeDelete(rootc); + SafeDel(rootc); break; } } @@ -462,7 +462,7 @@ int XrdROOTMgr::DoDirectiveRootSys(char *val, XrdOucStream *cfg, bool) fROOT.push_back(rootc); } else { TRACE(XERR, "could not validate "<<rootc->Export()); - SafeDelete(rootc); + SafeDel(rootc); } } } diff --git a/proof/proofplayer/src/TProofPlayer.cxx b/proof/proofplayer/src/TProofPlayer.cxx index ab9e65cc73ac903dbd3040ea15dc49aaa2b4f528..28052cb9cc920261515f4f9f774464ff44491b95 100644 --- a/proof/proofplayer/src/TProofPlayer.cxx +++ b/proof/proofplayer/src/TProofPlayer.cxx @@ -2406,13 +2406,13 @@ Long64_t TProofPlayerRemote::Finalize(Bool_t force, Bool_t sync) if (!fCreateSelObj) { fInput->Remove(fSelector); fOutput->Remove(fSelector); - output->Remove(fSelector); + if (output) output->Remove(fSelector); } // We have transferred copy of the output objects in TQueryResult, // so now we can cleanup the selector, making sure that we do not // touch the output objects - output->SetOwner(kFALSE); + if (output) output->SetOwner(kFALSE); if (fCreateSelObj) SafeDelete(fSelector); // Delete fOutput (not needed anymore, cannot be finalized twice), diff --git a/proof/proofplayer/src/TProofPlayerLite.cxx b/proof/proofplayer/src/TProofPlayerLite.cxx index 770133268110d4369f55bff45819ce210a8ae09f..93cdbc1646a7e8101c8a9de33cf2b4f20b502b68 100644 --- a/proof/proofplayer/src/TProofPlayerLite.cxx +++ b/proof/proofplayer/src/TProofPlayerLite.cxx @@ -386,13 +386,13 @@ Long64_t TProofPlayerLite::Finalize(Bool_t force, Bool_t sync) if (!fCreateSelObj) { fInput->Remove(fSelector); fOutput->Remove(fSelector); - output->Remove(fSelector); + if (output) output->Remove(fSelector); } // We have transferred copy of the output objects in TQueryResult, // so now we can cleanup the selector, making sure that we do not // touch the output objects - output->SetOwner(kFALSE); + if (output) output->SetOwner(kFALSE); if (fCreateSelObj) SafeDelete(fSelector); // Delete fOutput (not needed anymore, cannot be finalized twice), diff --git a/proof/proofx/src/TXProofMgr.cxx b/proof/proofx/src/TXProofMgr.cxx index 9dd64842b8f728da5d4a0d4ee619c130a7443457..22d1f90ad511d487a6019ba0d33c8691f05263c0 100644 --- a/proof/proofx/src/TXProofMgr.cxx +++ b/proof/proofx/src/TXProofMgr.cxx @@ -772,8 +772,7 @@ Int_t TXProofMgr::SendMsgToUsers(const char *msg, const char *usr) const Int_t kMAXBUF = 32768; char buf[kMAXBUF] = {0}; char *p = &buf[0]; - Int_t space = kMAXBUF - 1; - Int_t len = 0; + size_t space = kMAXBUF - 1; Int_t lusr = 0; // A specific user? @@ -784,6 +783,7 @@ Int_t TXProofMgr::SendMsgToUsers(const char *msg, const char *usr) space -= lusr; } + ssize_t len = 0; // Is it from file ? if (!gSystem->AccessPathName(msg, kFileExists)) { // From file: can we read it ? @@ -798,14 +798,27 @@ Int_t TXProofMgr::SendMsgToUsers(const char *msg, const char *usr) return -1; } // Determine the number of bytes to be read from the file. - Int_t left = (Int_t) lseek(fileno(f), (off_t) 0, SEEK_END); - lseek(fileno(f), (off_t) 0, SEEK_SET); + size_t left = 0; + off_t rcsk = lseek(fileno(f), (off_t) 0, SEEK_END); + if ((rcsk != (off_t)(-1))) { + left = (size_t) rcsk; + if ((lseek(fileno(f), (off_t) 0, SEEK_SET) == (off_t)(-1))) { + Error("SendMsgToUsers", "cannot rewind open file (seek to 0)"); + fclose(f); + return -1; + } + } else { + Error("SendMsgToUsers", "cannot get size of open file (seek to END)"); + fclose(f); + return -1; + } // Now readout from file - Int_t wanted = left; + size_t wanted = left; if (wanted > space) { wanted = space; Warning("SendMsgToUsers", - "requested to send %d bytes: max size is %d bytes: truncating", left, space); + "requested to send %lld bytes: max size is %lld bytes: truncating", + (Long64_t)left, (Long64_t)space); } do { while ((len = read(fileno(f), p, wanted)) < 0 && @@ -817,7 +830,7 @@ Int_t TXProofMgr::SendMsgToUsers(const char *msg, const char *usr) } // Update counters - left -= len; + left = (len >= (ssize_t)left) ? 0 : left - len; p += len; wanted = (left > kMAXBUF-1) ? kMAXBUF-1 : left; @@ -827,9 +840,10 @@ Int_t TXProofMgr::SendMsgToUsers(const char *msg, const char *usr) } else { // Add the message to the buffer len = strlen(msg); - if (len > space) { + if (len > (ssize_t)space) { Warning("SendMsgToUsers", - "requested to send %d bytes: max size is %d bytes: truncating", len, space); + "requested to send %lld bytes: max size is %lld bytes: truncating", + (Long64_t)len, (Long64_t)space); len = space; } memcpy(p, msg, len); diff --git a/proof/proofx/src/TXSocket.cxx b/proof/proofx/src/TXSocket.cxx index d7d0f83fb9a088301769677200d8e8b6369d4af0..696555e7a984c7fbc6df41f1d9afd1b5c7dde5d1 100644 --- a/proof/proofx/src/TXSocket.cxx +++ b/proof/proofx/src/TXSocket.cxx @@ -2124,9 +2124,13 @@ Int_t TXSocket::Reconnect() } if (gDebug > 0) { - Info("Reconnect", "%p (c:%p): attempt %s (logid: %d)", this, fConn, - ((fConn && fConn->IsValid()) ? "succeeded!" : "failed"), - fConn->GetLogConnID() ); + if (fConn) { + Info("Reconnect", "%p (c:%p): attempt %s (logid: %d)", this, fConn, + (fConn->IsValid() ? "succeeded!" : "failed"), + fConn->GetLogConnID() ); + } else { + Info("Reconnect", "%p (c:0x0): attempt failed", this); + } } // Done