Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

malloc.c:2368: sysmalloc: Assertion failed #2

Closed
Oliverwang opened this issue Apr 17, 2018 · 13 comments
Closed

malloc.c:2368: sysmalloc: Assertion failed #2

Oliverwang opened this issue Apr 17, 2018 · 13 comments

Comments

@Oliverwang
Copy link

bg_area.width 96 bg_area.height 95
fg_area.width 40 fg_area.height 39
area_resize_factor 1.5707 norm_bg_area.width 151 norm_bg_area.height 149
norm_target_sz.width 76 norm_target_sz.height 74
norm_pwp_search_area.width 150 norm_pwp_search_area.height 148
track: malloc.c:2368: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *(sizeof(size_t))) - 1)) & ~((2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long) old_end & pagemask) == 0)' failed.
Aborted

I use SSE2NEON.h replaced sse function and run on my phone, The above error occurred

@Oliverwang
Copy link
Author

test this sample is ok
SSE2NEON.h from https://github.com/jratcliff63367/sse2neon/blob/master/SSE2NEON.h
Any suggestion for the error? Thanks

@xuduo35
Copy link
Owner

xuduo35 commented Apr 17, 2018

Memory is corrupted. Please refer to this issue #1. You can try disable compiler optimize option, compile and run it again. Or you have to track how the content of those address mentioned in the assertion is changed, add some variables to memorize their values and compare them with current values at some checkpoints.

@Oliverwang
Copy link
Author

I used a memery error check tool, error report
==18014== Memcheck, a memory error detector
==18014== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==18014== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==18014== Command: build/stapleCC
==18014==
bg_area.width 96 bg_area.height 95
fg_area.width 40 fg_area.height 39
area_resize_factor 1.5707 norm_bg_area.width 151 norm_bg_area.height 149
norm_target_sz.width 76 norm_target_sz.height 74
norm_pwp_search_area.width 150 norm_pwp_search_area.height 148
wxhxc = 151 x 149 x 3
==18014== Invalid read of size 16
==18014== at 0x40993C: gradHist(float*, float*, float*, int, int, int, int, int, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40A5D4: fhog(float*, float*, float*, int, int, int, int, int, float) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40A95A: fhog(float*, float*, int, int, int, int*, int*, int*, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40B558: fhog28(cv::Mat&, cv::Mat const&, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40F3F1: STAPLE_TRACKER::getFeatureMap(cv::Mat&, char const*, cv::Mat&) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x419895: STAPLE_TRACKER::tracker_staple_train(cv::Mat const&, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40588E: main (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== Address 0x1dc6f99c is 98,556 bytes inside a block of size 98,568 alloc'd
==18014== at 0x4C2E858: calloc (vg_replace_malloc.c:711)
==18014== by 0x40A59D: fhog(float*, float*, float*, int, int, int, int, int, float) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40A95A: fhog(float*, float*, int, int, int, int*, int*, int*, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40B558: fhog28(cv::Mat&, cv::Mat const&, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40F3F1: STAPLE_TRACKER::getFeatureMap(cv::Mat&, char const*, cv::Mat&) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x419895: STAPLE_TRACKER::tracker_staple_train(cv::Mat const&, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40588E: main (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014==
==18014== Invalid write of size 8
==18014== at 0x40994B: gradHist(float*, float*, float*, int, int, int, int, int, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40A5D4: fhog(float*, float*, float*, int, int, int, int, int, float) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40A95A: fhog(float*, float*, int, int, int, int*, int*, int*, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40B558: fhog28(cv::Mat&, cv::Mat const&, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40F3F1: STAPLE_TRACKER::getFeatureMap(cv::Mat&, char const*, cv::Mat&) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x419895: STAPLE_TRACKER::tracker_staple_train(cv::Mat const&, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40588E: main (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== Address 0x1dc6f9a4 is 98,564 bytes inside a block of size 98,568 alloc'd
==18014== at 0x4C2E858: calloc (vg_replace_malloc.c:711)
==18014== by 0x40A59D: fhog(float*, float*, float*, int, int, int, int, int, float) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40A95A: fhog(float*, float*, int, int, int, int*, int*, int*, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40B558: fhog28(cv::Mat&, cv::Mat const&, int, int, float, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40F3F1: STAPLE_TRACKER::getFeatureMap(cv::Mat&, char const*, cv::Mat&) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x419895: STAPLE_TRACKER::tracker_staple_train(cv::Mat const&, bool) (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)
==18014== by 0x40588E: main (in /home/mrsy/project/track/STAPLE-master/build/stapleCC)

@Oliverwang
Copy link
Author

I writed a sample with opencv, only read a image and resize to 1280*720 , call getSubwindow fhog28 fhog31, have the same error

int main(){
Mat image = imread("lena.jpg",IMREAD_COLOR);

for (int i = 0; i < 100; i++)
{
    //Mat fhog_feature = fhog(image);
    //vector<Mat> feats;
    //split(fhog_feature, feats);

	cv::Mat resized;
	//cv::resize(image, resized, cv::Size(960, 640), 0, 0, cv::INTER_AREA);
	cv::resize(image, resized, cv::Size(1280, 720), 0, 0, cv::INTER_AREA);
	//cv::resize(image, resized, cv::Size(151, 149), 0, 0, cv::INTER_AREA);
	
	cv::Point_<float> centerCoor = cv::Point_<float>(514.5, 439);
	//cv::Point_<float> centerCoor = cv::Point_<float>(510.5, 411);
	cv::Size norm_bg_area = cv::Size(151, 149);
	cv::Size bg_area = cv::Size(96, 95);
	cv::Mat im_patch_bg;
	getSubwindow(resized, centerCoor, norm_bg_area, bg_area, im_patch_bg);
	
	cv::MatND xt;
	fhog28(xt, im_patch_bg, 4, 9);
	std::cout<<"##############fhog28 = "<<i<<std::endl;
	
	cv::MatND temp;
    fhog31(temp, im_patch_bg, 4, 9);
	std::cout<<"##############fhog31 = "<<i<<std::endl;
}
#if 0
for (size_t i = 0; i < feats.size(); i++) {
    cout<<feats[i]<<endl;
    imshow("feat", feats[i]);
    waitKey();
}
#endif


return 0;

}

@Oliverwang
Copy link
Author

Oliverwang commented Apr 18, 2018

test are all on ubuntu16.04
if resized image to cv::Size(151, 149) , then call fhog28 fhog32, No error occured

@xuduo35
Copy link
Owner

xuduo35 commented Apr 18, 2018

So in your sample code, the error is caused by wrong image size. From Valgrind output, it points to function gradHist. You can figure out which line of code is the source of message "==18014== Invalid read of size 16". Please check aMalloc and aFree function, do some change to debug. If you are running tracking code in single thread, maybe you can change aMalloc/aFree function to use a global static array as memory buffer for test.

@Oliverwang
Copy link
Author

pdollar/toolbox#8
is this issue ?

@xuduo35
Copy link
Owner

xuduo35 commented Apr 18, 2018

I read the post, but not very clear about the author's idea. It's better add some print around gradHist code lines to find the root cause.

@Oliverwang
Copy link
Author

modify code below can run without err

           // main rows, has top and bottom bins, use SSE for minor speedup
	if( softBin<0 ) 
		for( ; ; y++ )
		{
			std::cout<<"###########x = "<< x << "y = "<< y <<std::endl;
			yb0 = (int) yb;
			if(yb0>=hb-1)
				break;
			GHinit; 
			//_m0=sse::SET(M0[y]);
			if(hasLf) 
			{ 
				//_m=sse::SET(0,0,ms[1],ms[0]); 
				//GH(H0+O0[y],_m,_m0);
				H0[O0[y]] += M0[y]*ms[0];
				//H0[O0[y] + 3] += M0[y]*ms[1];
			}
			
			if(hasRt)
			{ 
				//_m=sse::SET(0,0,ms[3],ms[2]); 
				//GH(H0+O0[y]+hb,_m,_m0);
				H0[O0[y]+hb] += M0[y]*ms[3];
				//H0[O0[y]+hb + 3] += M0[y]*ms[2];
			}
			std::cout<<"o0[y] = "<<O0[y]<<" O0[y]+hb = "<< O0[y]+hb<<std::endl;
		}

@Oliverwang
Copy link
Author

test with sequence is ok

@xuduo35
Copy link
Owner

xuduo35 commented Apr 18, 2018

Nice 👍

@Oliverwang
Copy link
Author

But I don't know if this calculation of hog features is correct, it is not very clear that the hog principle

@xuduo35
Copy link
Owner

xuduo35 commented Apr 19, 2018

You can compare the result with PC's program. But make sure opencv is the same version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants