Advertisement

08.26.2008 at 02:13AM PDT, ID: 23677806 | Points: 500
[x]
Attachment Details

Dangling Pointer when using STL Vectors

Asked by BisCha in C / C++ / C# Editors and IDEs, Microsoft Visual C++

Tags:

Hi...can anyone tell me what is going worng out here. The memory leak detection tools says that there is a dangling pointer. [in the code "IndexList" is defined as - "typedef std::vector<long> IndexList;"]



Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
try
	{
		ADODB::_RecordsetPtr records = GetRecordsByIndex();
		_variant_t start = (long)ADODB::adBookmarkFirst;
		_variant_t indexArray = records->GetRows(ADODB::adGetRowsRest, start, _bstr_t(_T("Index")));
		
		long lUbound;
		TESTHR(SafeArrayGetUBound(indexArray.parray, 2, &lUbound));
		
		IndexList theIndexList;
		for(int record=0; record<lUbound+1; ++record)
		{
			long rgIndices[2];
			rgIndices[0] = 0; 
			rgIndices[1] = record;
			_variant_t result;
			result.vt = VT_I4;
			
			TESTHR(SafeArrayGetElement(indexArray.parray, rgIndices, &result));
			theIndexList.push_back((long)result.lVal); // This is where the error is reported
		}
		
		records->Close();
		records = NULL;
		
		return theIndexList;
	}
	catch(const _com_error& e)
	{
		if(HRESULT_CODE(e.Error()) == HRESULT_CODE(ADODB::adErrNoCurrentRecord))
		{
			// there are no records, so return an empty index list
			return IndexList();
		}
		else
		{
			throw;
		}
	}
 
Loading Advertisement...
 
[+][-]08.26.2008 at 05:01AM PDT, ID: 22313573

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.26.2008 at 07:23AM PDT, ID: 22315024

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628