[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I'm getting Memory uninitilize error from Rational Purfiy when I call for vector.Push_Back to store object of my class.

Posted on 2006-05-03
8
Medium Priority
?
365 Views
Last Modified: 2013-12-14
I'm getting Memory uninitilize error from Rational Purfiy when I call for vector.Push_Back to store object of my class.  The error is coming from the methor below, RetrieveUserAtt().

I'm working on a COM in-proc server using only the windows library.  I have declare vectors as follow:
     vector <CUserContextData> userDataObjects;


I've removed all the ifs in the class definition. I've also re-arrange and make sure all the initiliser are in the correct order the member data were declared. But I'm still getting memory uninitilize error in Rational Purify.The following are the class definition and the RetrieveUserAtt() code where the crash and memory error occurs.  I appreciate any help I can get.  Thank you.

HRESULT CUserPage::RetrieveUserAtt(int count, int listViewIndex, HWND hwndListView, LPWSTR contextNames)
{
      //GTiven a context, this method will locate the symark-UserContext data object if
      //it exists, and push it to the vector object.
      HRESULT hResult;
      _bstr_t context, temp, bstrAttribute;
      VARIANT var;
      VariantInit(&var);
      IADs *ptSyUserObject = NULL;

      context = contextNames;

      if(userSyUnifiedID != NULL)
            SetDlgItemInt(hwndDialog, IDC_GECOS_UNIFIEDID, userSyUnifiedID, TRUE);      

      _bstr_t syUserContextPath = L"LDAP://"  + bstrtServerDomain +
            L"/CN=" + userCN + L",CN=Users," + L"CN=" +context +
            L",CN=Contexts,CN=Unity,CN=Symark,CN=Program Data" +L"," + bstrDomainOnly;

      std::wstring lpcSyUserContextPath = syUserContextPath;

      hResult = ADsGetObject(T2CW(lpcSyUserContextPath.c_str()),IID_IADs,(void**)&ptSyUserObject);
      if(hResult!= S_OK)//New Sy User
      {
            if(hResult != SY_OBJECT_NOT_EXIST)//Error, not becuase SY user not found
                  DisplayError( hResult, L"Error obtaining Unix User Attributes. - RetrieveUserAtt");
            goto CleanUp;
      }

      if(SUCCEEDED(hResult))//Found symark-UserContext object
      {

            CUserContextData newUserData;
            //create the new userDataobject and push to Vector container
            newUserData.newObject = false;
            newUserData.UIDChanged = false;
            newUserData.NoChanged = true;;
            newUserData.listViewIndex = listViewIndex;

            newUserData.contextName = contextNames;

            //newUserData.symarkUserRef(userDN.operator const char *());
            newUserData.symarkUserRef = userDN;

            bstrAttribute = L"symark-Enabled";
            hResult =ptSyUserObject->Get(bstrAttribute.copy(), &var);
            if(hResult!= S_OK)//New Sy User
            {
                  DisplayError( hResult, L"Error obtaining symark-Enabled. - RetrieveUserAtt");
                  goto CleanUp;
            }
            if(var.boolVal)
                  newUserData.symarkEnabled = true;
            else
                  newUserData.symarkEnabled = false;
      VariantClear(&var);


//Get the symark-UseUnifiedUID
            bstrAttribute.Detach();
            bstrAttribute = L"symark-UseUnifiedUID";
            hResult =ptSyUserObject->Get(bstrAttribute, &var);
            if(hResult!= S_OK)//New Sy User
            {
                  DisplayError( hResult, L"Error obtaining symark-UseUnifiedUID. - RetrieveUserAtt");
                  goto CleanUp;
            }
            if(var.boolVal)
                  newUserData.bUnifiedID = true;
            else
                  newUserData.bUnifiedID = false;
            VariantClear(&var);
            bstrAttribute.Detach();
            bstrAttribute = L"symark-UseWinLogName";
            hResult =ptSyUserObject->Get(bstrAttribute, &var);
            if(hResult!= S_OK)//New Sy User
            {
                  DisplayError( hResult, L"Error obtaining symark-UseWinLogName. - RetrieveUserAtt");
                  goto CleanUp;
            }
            if(var.boolVal)
                  newUserData.bWinLogOn = true;
            else
                  newUserData.bWinLogOn = false;
            VariantClear(&var);


            if(!newUserData.bWinLogOn)//if not using winlogin then get the ind loginname
            {
                  bstrAttribute.Detach();
                  bstrAttribute = L"symark-LoginName";
                  hResult =ptSyUserObject->Get(bstrAttribute, &var);
                  if(hResult!= S_OK)//New Sy User
                  {
                        DisplayError( hResult, L"Error obtaining symark-LoginName. - RetrieveUserAtt");
                        goto CleanUp;
                  }
                  temp = var;
                  if(temp.length()>0)
                  {
                        newUserData.LoginName = (wchar_t*)(temp);

                  }
                  else
                        newUserData.LoginName = L"";
                  VariantClear(&var);
            }
            else
                  newUserData.LoginName = L"";


//Get the Shell
                  bstrAttribute.Detach();
                  bstrAttribute = L"symark-Shell";
                  hResult =ptSyUserObject->Get(bstrAttribute, &var);
                  if(hResult!= S_OK)//New Sy User
                  {
                        DisplayError( hResult, L"Error obtaining symark-Shell. - RetrieveUserAtt");
                        goto CleanUp;
                  }
                  temp = var.bstrVal;
                  if(temp.length()>0)
                  {
                        newUserData.shell = (wchar_t*)(temp);

                  }
                  else
                        newUserData.shell = L"";
                  VariantClear(&var);


//Get the Home
                  bstrAttribute.Detach();
                  bstrAttribute = L"symark-HomeDirectory";
                  hResult =ptSyUserObject->Get(bstrAttribute, &var);
                  if(hResult!= S_OK)//New Sy User
                  {
                        DisplayError( hResult, L"Error obtaining symark-HomeDirectory. - RetrieveUserAtt");
                        goto CleanUp;
                  }
                  temp = var.bstrVal;
                  if(temp.length()>0)
                  {
                        newUserData.homeDir = (wchar_t*)(temp);
                  }
                  else
                        newUserData.homeDir=L"";
                  VariantClear(&var);

//Get the primegroup
                  bstrAttribute.Detach();
                  bstrAttribute = L"symark-PrimaryGroupReference";
                  hResult =ptSyUserObject->Get(bstrAttribute, &var);
                  if(hResult!= S_OK)//New Sy User
                  {
                        DisplayError( hResult, L"Error obtaining symark-PrimaryGroupReference. - RetrieveUserAtt");
                        goto CleanUp;
                  }
                  temp = var.bstrVal;
                  if(temp.length()>0)
                  {
                        basic_string <char>::size_type indexCh1a;
                        //Assing the actual DN to the primarygroup field
                        newUserData.primaryGroup = (wchar_t*)(temp);
                        indexCh1a = newUserData.primaryGroup.find_first_of('=');
                        newUserData.groupCN = newUserData.primaryGroup;
                        newUserData.groupCN.erase(0, indexCh1a+1);
                        indexCh1a = newUserData.groupCN.find_first_of(',');

                        newUserData.groupCN.erase(indexCh1a, (newUserData.groupCN.length()-(indexCh1a)));

                        //Assing the index of the combox listing of this group
                        TCHAR tBuffer[ONE_K];
                        std::wstring gropuItem;
                        int groupListIndex;
                        LRESULT lResult;
                        for(groupListIndex = 0; groupListIndex <= comboSize-1; groupListIndex++)
                        {
                              lResult = SendDlgItemMessage(hwndDialog, IDC_PrimaryGroup, CB_GETLBTEXT,
                                    groupListIndex, (LPARAM)tBuffer);
                              std::wstring cn = T2W(tBuffer);
                              gropuItem = tBuffer;
                              if(gropuItem == newUserData.groupCN)
                                    break;
                        }

                        if(groupListIndex >= comboSize)
                              groupListIndex = 0;
                        newUserData.groupIndex = groupListIndex;
                  }
                  else
                        newUserData.primaryGroup=L"";
                  VariantClear(&var);

//Get the UID
            bstrAttribute.Detach();
            bstrAttribute = L"symark-UID";
            V_VT(&var) = VT_INT;
            hResult =ptSyUserObject->Get(bstrAttribute, &var);
            if(hResult!=S_OK)//New Sy User
            {
                  if((newUserData.bUnifiedID) && (userSyUnifiedID != NULL))
                        var.intVal = userSyUnifiedID;
                  else
                  {
                        DisplayError( hResult, L"Error obtaining symark-UID. - RetrieveUserAtt");
                        goto CleanUp;
                  }
            }
            else if(var.intVal == NULL)
            {
                  ::MessageBox(NULL, L"Fail to get either a UnifiedID or an Independent ID.", L"ID Error - RetrieveUserAtt", MB_ICONERROR | MB_OK);
                  hResult = E_FAIL;
                  goto CleanUp;
            }
            else
            {
                  newUserData.symarkUID = var.intVal;
                  newUserData.UID = var.intVal;
                  //if we're using unified id then make user they matched
                  if ((newUserData.bUnifiedID)&& (newUserData.symarkUID != userSyUnifiedID))
                  {
                        ::MessageBox(NULL, L"The symark-UID Doesn't match User UnifiedID.", L"Unified ID Error - RetrieveUserAtt", MB_ICONERROR | MB_OK);
                  }
            }
            
            userDataObjects.push_back(newUserData);
            //Set the checkBox status on the list control
            if(newUserData.symarkEnabled)
            {ListView_SetCheckState(hwndListView, listViewIndex, true); }
            else
            {ListView_SetCheckState(hwndListView, listViewIndex, false); }

            //Retrieve record and fill the Dialog screen and select the item
            if( count == 0)
            {
                  DisplayUserData(newUserData.contextName);
                  ListView_SetItemState(hwndListView, listViewIndex, LVIS_SELECTED, 0);
            }
            //Store in vector
            hResult = S_OK;
            
      }//end if we found the symark user object


CleanUp:
if(( count == 0) && (hResult == SY_OBJECT_NOT_EXIST))
{
      //display the userUnifiedID if the selected item 0 doesn't have a symark UserContext
      //Object exist already in the AD database
      FlushOut(contextNames, 0);
      EnableDataGroup(FALSE);
}
      if(ptSyUserObject)
            ptSyUserObject->Release();

      return hResult;

}---------class declaration
#pragma once

//typedef basic_string<wchar_t> wstring;

#include <string>


class CUserContextData
{
public:
            
    bool newObject, bWinLogOn, bUnifiedID, symarkEnabled, UIDChanged, newSyUserContext, NoChanged;
      std::wstring shell, homeDir, primaryGroup, symarkUserRef, LoginName, contextName, groupCN;
    int symarkUID, listViewIndex, UID, groupIndex;


//operator= Overload function
      CUserContextData& CUserContextData::operator=(const CUserContextData& newUserData)
      {
            if(this != &newUserData)
            {
            newObject = newUserData.newObject;
            bWinLogOn = newUserData.bWinLogOn;
            bUnifiedID = newUserData.bUnifiedID;
            symarkEnabled = newUserData.symarkEnabled;
            UIDChanged = newUserData.UIDChanged;
            newSyUserContext = newUserData.newSyUserContext;
            NoChanged = newUserData.NoChanged;
            symarkUID = newUserData.symarkUID;
            listViewIndex = newUserData.listViewIndex;
            UID = newUserData.UID;
            groupIndex = newUserData.groupIndex;
                   
            contextName = newUserData.contextName;
            groupCN = newUserData.groupCN;
                  
            LoginName = newUserData.LoginName;

            shell = newUserData.shell;

            homeDir = newUserData.homeDir;

            primaryGroup = newUserData.primaryGroup;

            symarkUserRef = newUserData.symarkUserRef;
            }
            return *this;
}//End operator= Overload

//Copy Constructor
 CUserContextData::CUserContextData(const CUserContextData &nud)
   :  newObject(nud.newObject), bWinLogOn(nud.bWinLogOn),  bUnifiedID(nud.bUnifiedID),
   symarkEnabled(nud.symarkEnabled), UIDChanged(nud.UIDChanged),shell(nud.shell),
   newSyUserContext(nud.newSyUserContext),NoChanged(nud.NoChanged),
   homeDir(nud.homeDir), primaryGroup(nud.primaryGroup), symarkUserRef(nud.symarkUserRef),
   LoginName(nud.LoginName), contextName(nud.contextName), groupCN(nud.groupCN),
   symarkUID(nud.symarkUID), listViewIndex(nud.UIDChanged), UID(nud.UID), groupIndex(nud.groupIndex)

 {
 }

//Default Constructor
 CUserContextData::CUserContextData(void) :  newObject(false), bWinLogOn(false),  bUnifiedID(false),
       symarkEnabled(false), UIDChanged(false), newSyUserContext(false), NoChanged(false),
       symarkUID(0), listViewIndex(0), UID(0), groupIndex(-1)

 {
 }

~CUserContextData(void)
{
}


};

----------------------------------------
This is the content of the newUserData, right before the push_back statement in RetrieveUserAtt() method I posted earlier. I don't see anything funning or un-initilize. Do you? Thanks.

- newUserData {newObject=false bWinLogOn=true bUnifiedID=true ...} CUserContextData
newObject false bool
bWinLogOn true bool
bUnifiedID true bool
symarkEnabled true bool
UIDChanged false bool
+ shell "/bin/shells/kern/symark" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ homeDir "/tmp/home/now" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ primaryGroup "CN=SymarkGroup,CN=Users,DC=windev,DC=symark,DC=com" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ symarkUserRef "CN=Administrator,CN=Users,DC=windev,DC=symark,DC=com" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ LoginName "" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ contextName "Accounting" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ wsContextName "Accounting" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
symarkUID 123 int
listViewIndex 0 int
UID 123 int


-------------------------------------------------------------------------------

Here is the content of the vector queue after the 1st push_back. It holds the boject infomration that I posted before. And they look fine to me too. I'm running this in VS2005 Debugging mode. I exit the program and everyting seems fine. I run this in Rational Purify and my program hangs and you saw the listing for the uninitilize memory problem. I also get a popup dialog box say"An handled win32 exception occurred in mmc$PC_C_WINDOWS_system32.exe[1000]"

- userDataObjects [1]({newObject=false bWinLogOn=true bUnifiedID=true ...}) std::vector<CUserContextData,std::allocator<CUserContextData> >
- [0] {newObject=false bWinLogOn=true bUnifiedID=true ...} CUserContextData
newObject false bool
bWinLogOn true bool
bUnifiedID true bool
symarkEnabled true bool
UIDChanged false bool
+ shell "/bin/shells/kern/symark" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ homeDir "/tmp/home/now" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ primaryGroup "CN=SymarkGroup,CN=Users,DC=windev,DC=symark,DC=com" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ symarkUserRef "CN=Administrator,CN=Users,DC=windev,DC=symark,DC=com" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ LoginName "" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ contextName "Accounting" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
+ wsContextName "Accounting" std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >
symarkUID 123 int
listViewIndex 0 int
UID 123 int
0
Comment
Question by:lapucca
  • 3
  • 2
6 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 16601544
Do you have a valid copy constructor for your CUserContextData class?
0
 
LVL 86

Expert Comment

by:jkr
ID: 16602063
>>I also get a popup dialog box say"An handled win32 exception occurred in
>>mmc$PC_C_WINDOWS_system32.exe[1000]"

To me that seems as one of the BSTR operations the Win32 API provides (and which can be found underneath these helpers) has encountered a problem, and not your code (except if you wrote system32.exe *g*). At least, that's what "An handled win32 exception occurred..." basically means. Chances are that the 'succesfull handling' actually left some litter behind...
0
 
LVL 86

Expert Comment

by:jkr
ID: 16602085
PS - some bacground info on "handled exceptions":

See http://support.microsoft.com/default.aspx?scid=kb;en-us;105675 ("INFO: First and Second Chance Exception Handling") and http://msdn.microsoft.com/library/en-us/debug/base/exception_handling_functions_for_debugging.asp ("Exception Handling Functions for Debugging"). The scoop is

"When an exception occurs in a process that is being debugged, the system notifies the debugger by passing the exception to it. This is known as first-chance notification. The system then suspends all threads in the process being debugged.

If the debugger does not handle the exception, the system attempts to locate an appropriate exception handler. If the system cannot locate an appropriate one, the system again notifies the debugger that an exception has occurred. This is known as last-chance notification. If the debugger does not handle the exception after the last-chance notification, the system terminates the process being debugged."

In other words, a "First-chance exception" means that an exception was successfully handled by the application. You can think of it as

long l;

__try // set up SEH frame
{
CopyMemory ( &l, 0, sizeof ( long)); // read from 0x00000000
}
__except( EXCEPTION_EXECUTE_HANDLER) // handler for current frame
{
puts ( "We knew that this would go wrong...");
}

A first chance exception is called so as it is passed to a debugger before the application 'sees' it. This is done by sending a 'EXCEPTION_DEBUG_EVENT' to the debugger, which can now decide whether it is passed to the application to handle it or 'ignore' it (e.g. like an 'EXCEPTION_BREAKPOINT' aka 'int 3')

The same applies to what Purify is reporting.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:lapucca
ID: 16602646
Hi Axter,
In the code I posted, there is a copy constructor inside the class declaration of CUserContextData.  There is also code for the operator= overload .  I've checked them several times, they're declared in the order these member varialbes are declare in the class.  Do you see a problem in my copy consturctor?

//Copy Constructor
 CUserContextData::CUserContextData(const CUserContextData &nud)
   :  newObject(nud.newObject), bWinLogOn(nud.bWinLogOn),  bUnifiedID(nud.bUnifiedID),
   symarkEnabled(nud.symarkEnabled), UIDChanged(nud.UIDChanged),shell(nud.shell),
   newSyUserContext(nud.newSyUserContext),NoChanged(nud.NoChanged),
   homeDir(nud.homeDir), primaryGroup(nud.primaryGroup), symarkUserRef(nud.symarkUserRef),
   LoginName(nud.LoginName), contextName(nud.contextName), groupCN(nud.groupCN),
   symarkUID(nud.symarkUID), listViewIndex(nud.UIDChanged), UID(nud.UID), groupIndex(nud.groupIndex)

 {
 }

//Default Constructor
 CUserContextData::CUserContextData(void) :  newObject(false), bWinLogOn(false),  bUnifiedID(false),
      symarkEnabled(false), UIDChanged(false), newSyUserContext(false), NoChanged(false),
      symarkUID(0), listViewIndex(0), UID(0), groupIndex(-1)

 {
 }
0
 

Author Comment

by:lapucca
ID: 16602720
Thanks jkr for the information on the exception message that I was getting.
So, if the debugger handles the exception, does that mean it's OK and I can just ignore that exception as long as the debugger handels it?  The problem is that another message window pops up and ask if I would like to start a new debug session by opening a new vs2005 or use the current one.  

Either current vs or a new vs session it's all the same.  It's in mmc (Micorost Mangement Console, where Active Directory runs) and it's either showing assembly code or it shows nothing and I can only exit.  Noway to debug this thing.
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 16608915
>>So, if the debugger handles the exception, does that mean it's OK and I can just ignore that exception

It's not the debugger, it is the application itself. It is only that when debugging (and Purify attaches to processes as a debugger) exceptions are passed to the debuger first before the application has even a chance to handle them.

>>It's in mmc

... so you don't even need to care about that. It's a problem by MS, and even if you knew how, you cannot fix it anyway.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question