CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Threaded View

  1. #1
    Join Date
    Aug 2004
    Posts
    61

    Memory Leak within worker thread

    I have a memory leak whenever this code is executed, any ideas on what I am doing wrong?

    Code:
    typedef struct ACC_MessageBox_Params
    {
    	int i;
    	CString ACC_ErrorBuffer;
    
    	ACC_MessageBox_Params(int Channel, CString AlarmMsg)
    	{
    		i = Channel;
    		ACC_ErrorBuffer = (LPCTSTR)AlarmMsg;
    	}
    }
    	PARAMS, *PPARAMS;
    
    
    ===============================================================
    THREAD #1
    
    AfxBeginThread(ACC_MessageBox, (PVOID) new ACC_MessageBox_Params(i, (LPCTSTR)ACC_ErrorBuffer));
    
    ===============================================================
    
    
    UINT ACC_MessageBox(PVOID p)
    {
    // Worker Thread Pass-In Variables (Channel & Alarm Message) -> i(int), ACC_ErrorBuffer(CString)
    PPARAMS pParams = (PPARAMS)p;
    
    // Header Include Files
    
    // Variable Declarations
    int	response;
    
    // User Defined Constants
    
    // Set Abnormal (Exception Error Handling) 
    set_terminate (myterminate);
    
    // Multithread Synchronization (Single Lock Object)
    CSingleLock	lock1(&GlobalMutex); // locks all SQL shared variables (RecordSet1) between threads
    CSingleLock	lock2(&GlobalMutex); // locks all TimeStamp and OutputFile shared variables between threads
    
    // Initialize
    
    // Start of Main Code
    	response = AfxMessageBox ((LPCTSTR)pParams->ACC_ErrorBuffer, MB_OKCANCEL|MB_ICONEXCLAMATION);
    	if (response == IDOK)
    	{
    		if (!lock2.IsLocked())
    		{
    			lock2.Lock();				
    			OutputFile << (LPCTSTR)TimeStampDT() << "Accucure.Main: MESSAGEBOX - Operator acknowledged alarm on Accucure Ch.0" << (pParams->i) + 1 << "\n";
    			lock2.Unlock();
    		}	
    		CureRemainTime[pParams->i] = 0.0;
    		ActualRadiance[pParams->i] = 0.0;
    	}
    	if(response == IDCANCEL)
    	{		
    		if (!lock2.IsLocked())
    		{
    			lock2.Lock();				
    			OutputFile << (LPCTSTR)TimeStampDT() << "Accucure.Main: MESSAGEBOX - Operator CLOSED window on Accucure alarm Ch.0" << (pParams->i) + 1 << ". Program will terminate.\n";
    			lock2.Unlock();
    		}	
    		Sleep(100);
    		delete pParams;
    		pParams = 0;
    		exit(0);
    	}
    ACC_Active_MessageBoxes[pParams->i] = false;
    delete pParams;
    pParams = 0;
    return (0);
    }
    Last edited by 99bobster99; June 11th, 2010 at 04:10 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured