Click here to Skip to main content
15,919,245 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralGetting Installed BHOs Pin
Liger_Zero_X5-Jul-04 23:10
Liger_Zero_X5-Jul-04 23:10 
GeneralRe: Getting Installed BHOs Pin
2249176-Jul-04 0:30
2249176-Jul-04 0:30 
GeneralRe: Getting Installed BHOs Pin
Liger_Zero_X6-Jul-04 0:56
Liger_Zero_X6-Jul-04 0:56 
GeneralRe: Getting Installed BHOs Pin
xcavin6-Jul-04 1:45
xcavin6-Jul-04 1:45 
GeneralRe: Getting Installed BHOs Pin
Liger_Zero_X6-Jul-04 2:11
Liger_Zero_X6-Jul-04 2:11 
GeneralRe: Getting Installed BHOs Pin
Michael P Butler6-Jul-04 1:44
Michael P Butler6-Jul-04 1:44 
GeneralRegisterDevice Pin
IceBerG715-Jul-04 23:05
IceBerG715-Jul-04 23:05 
Generalmalloc/free to new /delete error Pin
mcsherry5-Jul-04 22:45
mcsherry5-Jul-04 22:45 
Hi,

I've recently converted some C code into C++ but am now having problems with some of the memory allocation/deletion in it. The problem Im having is taht when I come to delete a float** I get an invalid heap error. I think I *may* be deleting the wrong bit of memory (not used pointers to pointers before). I've pasted the code fragment below and also the last few bits of the call stack where it crashes.
Can anyone spot what I'm doing wrong and also how I can fix it!

cheers,

void CTestprogDlg::OnButton1()
{
float **xMeas ;

// TODO: Add your control notification handler code here
xMeas = OpenMatrix ( 0,
1,
0,
0 ) ;

xMeas [0][0] = 1 ;

CloseMatrix ( xMeas,
0,
1,
0,
0 ) ;
}

float**
CTestprogDlg::
OpenMatrix ( long int nrl,
long int nrh,
long int ncl,
long int nch )
//allocate a float matrix with subscript range m[nrl..nrh][ncl..nch]
{
long int i ;
long int nrow = nrh - nrl + 1 ;
long int ncol = nch - ncl + 1 ;

float **m ;

/* allocate pointers to rows */
//m = (float **) malloc ( (size_t) ( ( nrow + NR_END ) * sizeof ( float*) ) ) ;
// TBD - changed to new instead of malloc
m = new float* [ nrow + NR_END ] ;

if ( !m )
{
AfxMessageBox ( "Matrix Allocation Error!!\n" ) ;
exit ( 1 ) ;
}

m += NR_END ;
m -= nrl ;

/* allocate rows and set pointers to them */
//m[nrl] = (float*) malloc ( (size_t) ( ( nrow * ncol + NR_END ) * sizeof ( float ) ) ) ;
// TBD - changed to new instead of malloc
m [nrl] = new float [ nrow * ncol + NR_END ] ;

if ( !m [nrl] )
{
AfxMessageBox ( "Matrix Allocation Error 2!!\n" ) ;
exit ( 1 ) ;
}

m [nrl] += NR_END ;
m [nrl] -= ncl ;

for ( i = nrl + 1 ; i <= nrh ; i++ )
{
m [i] = m [i - 1] + ncol ;
}

return ( m ) ;
}

void
CTestprogDlg::
CloseMatrix ( float **m,
long int nrl,
long int nrh,
long int ncl,
long int nch )
//free a float matrix opened with OpenMatrix
{
//free ( (char*) ( m [nrl] + ncl - NR_END ) ) ;
//free ( (char*) ( m + nrl - NR_END ) ) ;

// TBD - check that we want to delete all of v
// also check that this is deleting all of the object as it is a float**

long int nrow = nrh - nrl + 1 + NR_END ;

for ( int d1 = 0 ; d1 < nrow ; d1++ )
{
delete [] m [d1] ;
}

delete [] m ;
}

NTDLL! 77f9f9df()
NTDLL! 77fb4966()
NTDLL! 77f8b3d2()
KERNEL32! 77e944cd()
_CrtIsValidHeapPointer(const void * 0x011e766c) line 1697
_free_dbg_lk(void * 0x011e766c, int 1) line 1044 + 9 bytes
_free_dbg(void * 0x011e766c, int 1) line 1001 + 13 bytes
operator delete(void * 0x011e766c) line 351 + 12 bytes
CTestprogDlg::CloseMatrix(float * * 0x011e7624, long 0, long 1, long 0, long 0) line 176 + 21 bytes
GeneralRe: malloc/free to new /delete error Pin
Roger Allen6-Jul-04 4:08
Roger Allen6-Jul-04 4:08 
GeneralRe: malloc/free to new /delete error Pin
mcsherry8-Jul-04 21:47
mcsherry8-Jul-04 21:47 
GeneralLR_DEFAULTSIZE|LR_LOADFROMFILE in WinCE Pin
Anonymous5-Jul-04 22:42
Anonymous5-Jul-04 22:42 
Questionhow to set CTabCtrl background color? Pin
alma5-Jul-04 22:41
alma5-Jul-04 22:41 
Generalinitailize parallel port Pin
Member 12191245-Jul-04 22:12
Member 12191245-Jul-04 22:12 
GeneralRe: initailize parallel port Pin
Rory Solley5-Jul-04 23:06
Rory Solley5-Jul-04 23:06 
GeneralRe: initailize parallel port Pin
Ryan Binns5-Jul-04 23:11
Ryan Binns5-Jul-04 23:11 
General#import for COM Dll Pin
Vaibhav Sanghavi5-Jul-04 21:44
Vaibhav Sanghavi5-Jul-04 21:44 
GeneralRe: #import for COM Dll Pin
Roger Stoltz5-Jul-04 22:13
Roger Stoltz5-Jul-04 22:13 
GeneralRe: #import for COM Dll Pin
Vaibhav...5-Jul-04 22:28
sussVaibhav...5-Jul-04 22:28 
GeneralRe: #import for COM Dll Pin
Roger Stoltz6-Jul-04 0:27
Roger Stoltz6-Jul-04 0:27 
GeneralRe: #import for COM Dll Pin
Vaibhav Sanghavi11-Jul-04 23:39
Vaibhav Sanghavi11-Jul-04 23:39 
GeneralRe: #import for COM Dll Pin
Roger Stoltz12-Jul-04 14:52
Roger Stoltz12-Jul-04 14:52 
GeneralRe: #import for COM Dll Pin
Vaibhav Sanghavi12-Jul-04 18:55
Vaibhav Sanghavi12-Jul-04 18:55 
GeneralRe: #import for COM Dll Pin
Michael P Butler6-Jul-04 1:17
Michael P Butler6-Jul-04 1:17 
GeneralMSHFlexgrid ~ custom Autoresize Pin
V.5-Jul-04 21:27
professionalV.5-Jul-04 21:27 
Generalinheritance Pin
xcavin5-Jul-04 21:11
xcavin5-Jul-04 21:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.