Resized windows cause dbgheap.c error

Hi every advance.
I use resized windows in my code by VC++.
It’s strange when resize sometime is cause error but sometimes is work
well…
Not matter error is happen or not,my video is contiune to display.
my code like that:
////////////////////////////////////////////////////////////////////////////
//////////////////////
screen = SDL_SetVideoMode(320,240, 0,SDL_SWSURFACE|SDL_VIDEORESIZE );
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set 32024024 video mode: %s\n”,
SDL_GetError());
exit(1);
SDL_SetColors(screen, colors, 0, 256);
}
////////////////////////////////////////////////////////////////////////////
///////////////////////
if(m_xdim!=oldXdimm||m_ydim!=oldYdimm)
{
user_event.type=SDL_VIDEORESIZE;
user_event.resize.w=m_xdim;
user_event.resize.h=m_ydim;
SDL_PushEvent(&user_event);
oldXdimm=m_xdim;
oldYdimm=m_ydim;
ChangeSize=TRUE;
}
////////////////////////////////////////////////////////////////////////////
/////////////////////
if(ChangeSize==TRUE)
{
SDL_FreeSurface(screen);
mask=(SDL_VIDEORESIZEMASK);
SDL_PeepEvents(&user_event,1,SDL_GETEVENT,mask);
SDL_SetVideoMode(m_xdim,m_ydim, 0,SDL_SWSURFACE|SDL_VIDEORESIZE );
ChangeSize=FALSE;
}
image=SDL_CreateRGBSurfaceFrom( buffer,m_xdim,m_ydim,24,m_xdim*3,0,0,0,0);
SDL_SetColors(image, colors, 0, 256);
dest.x = 0;
dest.y = 0;
dest.w = m_xdim;
dest.h = m_ydim;
SDL_BlitSurface(image,NULL,screen,&dest);
SDL_FreeSurface(image);
SDL_UpdateRects(screen, 1, &dest);
}

Thx very much…