Fixed problem with file sheduled file upload. Fixed some memory leaks Fixes #1187
authorzev <zev@radensolutions.com>
Tue, 7 Jun 2016 15:40:54 +0000 (18:40 +0300)
committerzev <zev@radensolutions.com>
Tue, 7 Jun 2016 15:40:54 +0000 (18:40 +0300)
src/server/core/ap_jobs.cpp
src/server/core/job.cpp
src/server/core/session.cpp
src/server/core/upload_job.cpp
src/server/include/nxcore_jobs.h
src/server/libnxsrv/apinfo.cpp

index b45e67d..4c7b01c 100644 (file)
@@ -163,7 +163,7 @@ ServerJobResult PolicyDeploymentJob::run()
 /**
  * Serializes job parameters into TCHAR line separated by ';'
  */
-const TCHAR *PolicyDeploymentJob::serializeParameters()
+TCHAR *PolicyDeploymentJob::serializeParameters()
 {
    String params;
    params.append(m_policy->getId());
@@ -177,7 +177,9 @@ const TCHAR *PolicyDeploymentJob::serializeParameters()
  */
 void PolicyDeploymentJob::rescheduleExecution()
 {
-   AddOneTimeScheduledTask(_T("Policy.Deploy"), time(NULL) + getNextJobExecutionTime(), serializeParameters(), 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   TCHAR *params = serializeParameters();
+   AddOneTimeScheduledTask(_T("Policy.Deploy"), time(NULL) + getNextJobExecutionTime(), params, 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   free(params);
 }
 
 
@@ -318,7 +320,7 @@ ServerJobResult PolicyUninstallJob::run()
 /**
  * Serializes job parameters into TCHAR line separated by ';'
  */
-const TCHAR *PolicyUninstallJob::serializeParameters()
+TCHAR *PolicyUninstallJob::serializeParameters()
 {
    String params;
    params.append(m_policy->getId());
@@ -332,5 +334,7 @@ const TCHAR *PolicyUninstallJob::serializeParameters()
  */
 void PolicyUninstallJob::rescheduleExecution()
 {
-   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getNextJobExecutionTime(), serializeParameters(), 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   TCHAR *params = serializeParameters();
+   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getNextJobExecutionTime(), params, 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   free(params);
 }
index aa341d1..5262770 100644 (file)
@@ -384,7 +384,7 @@ const TCHAR *ServerJob::getAdditionalInfo()
 /**
  * Serializes job parameters into TCHAR line separated by ';'
  */
-const TCHAR *ServerJob::serializeParameters()
+TCHAR *ServerJob::serializeParameters()
 {
    return _tcsdup(_T(""));
 }
index 34af390..dce6c0e 100644 (file)
@@ -12329,17 +12329,7 @@ void ClientSession::uploadFileToAgent(NXCPMessage *request)
                                TCHAR *remoteFile = request->getFieldAsString(VID_DESTINATION_FILE_NAME);
                                if (localFile != NULL)
                                {
-                                       int nLen;
-                                       TCHAR fullPath[MAX_PATH];
-
-                                       // Create full path to the file store
-                                       _tcscpy(fullPath, g_netxmsdDataDir);
-                                       _tcscat(fullPath, DDIR_FILES);
-                                       _tcscat(fullPath, FS_PATH_SEPARATOR);
-                                       nLen = (int)_tcslen(fullPath);
-                                       nx_strncpy(&fullPath[nLen], GetCleanFileName(localFile), MAX_PATH - nLen);
-
-                                       ServerJob *job = new FileUploadJob((Node *)object, fullPath, remoteFile, m_dwUserId,
+                                       ServerJob *job = new FileUploadJob((Node *)object, localFile, remoteFile, m_dwUserId,
                                                                           request->getFieldAsUInt16(VID_CREATE_JOB_ON_HOLD) ? true : false);
                                        if (AddJob(job))
                                        {
index d043c78..7f4574f 100644 (file)
@@ -78,6 +78,7 @@ FileUploadJob::FileUploadJob(Node *node, const TCHAR *localFile, const TCHAR *re
        setDescription(buffer);
 
        m_localFile = _tcsdup(localFile);
+       setLocalFileFullPath();
        m_remoteFile = (remoteFile != NULL) ? _tcsdup(remoteFile) : NULL;
 
        _sntprintf(buffer, 1024, _T("Local file: %s; Remote file: %s"), m_localFile, CHECK_NULL(m_remoteFile));
@@ -93,7 +94,6 @@ FileUploadJob::FileUploadJob(TCHAR* params, UINT32 node, UINT32 userId)
        if(m_node != NULL)
       m_node->incRefCount();
 
-
    StringList fileList(params, _T(","));
    if(fileList.size() < 2)
    {
@@ -109,7 +109,8 @@ FileUploadJob::FileUploadJob(TCHAR* params, UINT32 node, UINT32 userId)
        setDescription(buffer);
 
        m_localFile = _tcsdup(fileList.get(0));
-       m_remoteFile = (fileList.size() == 3) ? _tcsdup(fileList.get(1)) : NULL;
+       setLocalFileFullPath();
+       m_remoteFile = fileList.get(1)[0] != 0 ? _tcsdup(fileList.get(1)) : NULL;
 
        _sntprintf(buffer, 1024, _T("Local file: %s; Remote file: %s"), m_localFile, CHECK_NULL(fileList.get(1)));
        m_info = _tcsdup(buffer);
@@ -117,6 +118,20 @@ FileUploadJob::FileUploadJob(TCHAR* params, UINT32 node, UINT32 userId)
        m_fileSize = 0;
 }
 
+void FileUploadJob::setLocalFileFullPath()
+{
+   int nLen;
+   TCHAR fullPath[MAX_PATH];
+
+   // Create full path to the file store
+   _tcscpy(fullPath, g_netxmsdDataDir);
+   _tcscat(fullPath, DDIR_FILES);
+   _tcscat(fullPath, FS_PATH_SEPARATOR);
+   nLen = (int)_tcslen(fullPath);
+   nx_strncpy(&fullPath[nLen], GetCleanFileName(m_localFile), MAX_PATH - nLen);
+   m_localFileFullPath = _tcsdup(fullPath);
+}
+
 /**
  *  Destructor
  */
@@ -124,6 +139,7 @@ FileUploadJob::~FileUploadJob()
 {
        m_node->decRefCount();
        safe_free(m_localFile);
+       safe_free(m_localFileFullPath);
        safe_free(m_remoteFile);
        safe_free(m_info);
 }
@@ -151,8 +167,8 @@ ServerJobResult FileUploadJob::run()
        AgentConnectionEx *conn = m_node->createAgentConnection();
        if (conn != NULL)
        {
-               m_fileSize = (INT64)FileSize(m_localFile);
-               UINT32 rcc = conn->uploadFile(m_localFile, m_remoteFile, uploadCallback, this);
+               m_fileSize = (INT64)FileSize(m_localFileFullPath);
+               UINT32 rcc = conn->uploadFile(m_localFileFullPath, m_remoteFile, uploadCallback, this);
                if (rcc == ERR_SUCCESS)
                {
                        success = JOB_RESULT_SUCCESS;
@@ -205,7 +221,7 @@ const TCHAR *FileUploadJob::getAdditionalInfo()
 /**
  * Serializes job parameters into TCHAR line separated by ';'
  */
-const TCHAR *FileUploadJob::serializeParameters()
+TCHAR *FileUploadJob::serializeParameters()
 {
    String params;
    params.append(m_localFile);
@@ -221,6 +237,8 @@ const TCHAR *FileUploadJob::serializeParameters()
  */
 void FileUploadJob::rescheduleExecution()
 {
-   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getNextJobExecutionTime(), serializeParameters(), 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   TCHAR *param = serializeParameters();
+   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getNextJobExecutionTime(), param, 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   free(param);
 }
 
index 1814d0d..ebec557 100644 (file)
@@ -131,7 +131,7 @@ public:
        void setOwningQueue(ServerJobQueue *queue);
 
        void fillMessage(NXCPMessage *msg);
-       virtual const TCHAR *serializeParameters();
+       virtual TCHAR *serializeParameters();
        virtual void rescheduleExecution();
        int getNextJobExecutionTime();
 };
@@ -186,6 +186,7 @@ protected:
 
        Node *m_node;
        TCHAR *m_localFile;
+       TCHAR *m_localFileFullPath;
        TCHAR *m_remoteFile;
        TCHAR *m_info;
        INT64 m_fileSize;
@@ -201,8 +202,9 @@ public:
        FileUploadJob(TCHAR* params, UINT32 node, UINT32 userId);
        virtual ~FileUploadJob();
 
-       virtual const TCHAR *serializeParameters();
+       virtual TCHAR *serializeParameters();
        virtual void rescheduleExecution();
+       void setLocalFileFullPath();
 };
 
 /**
@@ -257,7 +259,7 @@ public:
    PolicyDeploymentJob(const TCHAR* params, UINT32 node, UINT32 userId);
        virtual ~PolicyDeploymentJob();
 
-       virtual const TCHAR *serializeParameters();
+       virtual TCHAR *serializeParameters();
        virtual void rescheduleExecution();
 };
 
@@ -278,7 +280,7 @@ public:
    PolicyUninstallJob(const TCHAR* params, UINT32 node, UINT32 userId);
        virtual ~PolicyUninstallJob();
 
-       virtual const TCHAR *serializeParameters();
+       virtual TCHAR *serializeParameters();
        virtual void rescheduleExecution();
 };
 
index 1ad489c..28e7092 100644 (file)
@@ -63,6 +63,7 @@ AgentPolicyInfo::~AgentPolicyInfo()
 {
    for(int i = 0; i < m_size; i++)
                free(m_serverInfoList[i]);
+   free(m_serverInfoList);
        free(m_serverIdList);
        free(m_typeList);
        free(m_guidList);