# include "stdio.h"
# include "stdlib. H"
# include "string. H"
/* * * width cell matrix are how many units/* *
Int mMatrixLength=0;
Each cell width */*/
Float mMapUnitLength=0.2;
/* */map data structure
Struct mapUnit
{
Float * texCoor;//control in the box how to fill the picture
Float * are;//vertices, x, y, z, x, y, z
Char * filePath.//the current load diagram block filePath
Char * pixels;//diagram block pixels
Char drawFinished;//load the tiles after the change, the tag is loaded to the corresponding pixel node
};
Typedef struct mapUnit mapUnit;
//block matrix (2 d pointer)
MapUnit * mMapUnitMatrix;
Void init () {
//create a map (there is a problem, accidental flash back)
MMatrixLength=4;//the original coordinates to move to the upper left corner, so screen width changed into 2 f, add 1 more to transverse longitudinal line of invisible buffer side
MMapUnitMatrix=(MapUnit *) malloc (sizeof (MapUnit) * mMatrixLength * mMatrixLength);
int i;
For (I=0; I & lt; MMatrixLength * mMatrixLength; I++)
{
MapUnit unit=mMapUnitMatrix [I];
Unit.and texCoor=(float *) malloc (sizeof (float) * 12);//assignment unified TexCoor
Unit.and are=(float *) malloc (sizeof (float) * 18);//assign each figure a block unit in accordance with their position coordinates
Unit. The drawFinished=0;//each new tiles are not completed the pixel filling
Unit.and pixels=(char *) malloc (36);
}
Printf (" init \ n ");
}
Void destroy () {
Printf (" destroy: % llu \ n ", mMapUnitMatrix);
int i;
For (I=0; I & lt; MMatrixLength * mMatrixLength; I++)
{
MapUnit unit=mMapUnitMatrix [I];
Free (unit.and pixels);
Unit. The pixels=NULL;
Free (unit. Are);
Unit. Are=NULL;
Free (unit.and texCoor);
Unit.and texCoor=NULL;
Free (unit.and filePath);
}
Free (mMapUnitMatrix);
MMapUnitMatrix=NULL;
}
MapUnit getUnit (int x, int y) {
Return mMapUnitMatrix [y * mMatrixLength + x];
}
Int main ()
{
While (1)
{
init();
Destroy ();
//init ();
//destroy ();
}
return 0;
}
When the destory the second time will be:
Init
Destroy: 94816647983120
Init
Destroy: 94816647983120
* * * Error in `./bigMatrix1. Bin ': free () : invalid pointer: 0 x00007f257f3fcb58 * * *
=======Backtrace:=========
/lib/x86_64 - - the gnu/Linux libc. So. 6 (+ 0 x70bfb x7f257f0d3bfb [0])
/lib/x86_64 - - the gnu/Linux libc. So. 6 (+ 0 x76fc6 x7f257f0d9fc6 [0])
/lib/x86_64 - - the gnu/Linux libc. So. 6 (+ 0 x7780e x7f257f0da80e [0])
./bigMatrix1. Bin (+ 0 x8ff) x563c383e58ff [0]
./bigMatrix1. Bin (+ 0 x9e3) x563c383e59e3 [0]
/lib/x86_64 - - the gnu/Linux libc. So. 6 (__libc_start_main + 0 xf1) x7f257f0832e1 [0]
./bigMatrix1. Bin (+ 0 x67a) x563c383e567a [0]
=======the Memory map:========
C383e5000-563 c383e6000 r - 563 xp 00000000 likeness 2052556/media/chenjiezhu/work2/work/project/AndroidProject/AndroidProject/WhiteBoardCJZ/app/test/bigMatrix1 bin
C385e6000 r c385e5000 563-563-2052556/media/chenjiezhu/p 00000000 likeness work2/work/project/AndroidProject/AndroidProject/WhiteBoardCJZ/app/test/bigMatrix1 bin
563 c385e7000 rw c385e6000-563 - p 00001000 likeness 2052556/media/chenjiezhu/work2/work/project/AndroidProject/AndroidProject WhiteBoardCJZ/app/test/bigMatrix1 bin
563 c38a14000 rw c389f3000-563 - p 00000000 00:00 0 [heap]
7 f2578000000-7 f2578021000 rw - p 00000000 00:00 0
7 f2578021000-7 f257c000000 - p 00000000 00:00 0
7 f257ee4c000-7 f257ee62000 r - 00000000 08:22 5378864 xp/usr/lib/x86_64 - - the gnu/Linux libgcc_s. So. 1
7 f257ee62000-7 f257f061000-00016000 08:22 5378864 p/usr/lib/x86_64 - - the gnu/Linux libgcc_s. So. 1
7 f257f061000-7 f257f062000 r - 00015000 08:22 5378864 p/usr/lib/x86_64 - - the gnu/Linux libgcc_s. So. 1
7 f257f062000-7 f257f063000 rw - p 00016000 08:22 5378864/usr/lib/x86_64 - - the gnu/Linux libgcc_s. So. 1
7 f257f063000-7 f257f1f8000 r - 00000000 08:22 5378540 xp/usr/lib/x86_64 - - the gnu/Linux libc - 2.24. So
7 f257f1f8000-7 f257f3f8000-00195000 08:22 5378540 p/usr/lib/x86_64 - - the gnu/Linux libc - 2.24. So
7 f257f3f8000-7 f257f3fc000 r - 00195000 08:22 5378540 p/usr/lib/x86_64 - - the gnu/Linux libc - 2.24. So
7 f257f3fc000-7 f257f3fe000 rw - p 00199000 08:22 5378540/usr/lib/x86_64 - - the gnu/Linux libc - 2.24. So
7 f257f3fe000-7 f257f402000 rw - p 00000000 00:00 0
7 f257f402000-7 f257f425000 r - 00000000 08:22 5378088 xp/usr/lib/x86_64 - - the gnu/Linux ld - 2.24. So
7 f257f600000-7 f257f602000 rw - p 00000000 00:00 0
7 f257f621000-7 f257f625000 rw - p 00000000 00:00 0
7 f257f625000-7 f257f626000 r - 00023000 08:22 5378088 p/usr/lib/x86_64 - - the gnu/Linux ld - 2.24. So
7 f257f626000-7 f257f627000 rw - p 00024000 08:22 5378088/usr/lib/x86_64 - - the gnu/Linux ld - 2.24. So
7 f257f627000-7 f257f628000 rw - p 00000000 00:00 0
7 ffccee76000-7 ffccee99000 rw - p 00000000 00:00 0 (stack)
7 ffccef87000-7 ffccef8a000 r - 00000000 00:00 0 p [vvar]
7 ffccef8a000-7 ffccef8c000 r - 00000000 xp 00:00 0 (vdso)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull