Bug 207 - Fixed memory corruption due to incorrect shared memory offsets.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1613 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2005-11-22 10:39:51 +00:00
parent 01bf61363c
commit 9e03d55a8c
1 changed files with 11 additions and 6 deletions

View File

@ -137,7 +137,11 @@ void Monitor::Setup()
Debug( 1, ( "monitor purpose=%d", purpose ));
int shared_data_size = sizeof(SharedData)+sizeof(TriggerData)+(image_buffer_count*sizeof(time_t))+(image_buffer_count*camera->ImageSize());
int shared_data_size = sizeof(SharedData)
+ sizeof(TriggerData)
+ (image_buffer_count*sizeof(struct timeval))
+ (image_buffer_count*camera->ImageSize());
Debug( 1, ( "shm.size=%d", shared_data_size ));
shmid = shmget( (config.shm_key&0xffffff00)|id, shared_data_size, IPC_CREAT|0700 );
if ( shmid < 0 )
@ -146,13 +150,16 @@ void Monitor::Setup()
exit( -1 );
}
unsigned char *shm_ptr = (unsigned char *)shmat( shmid, 0, 0 );
shared_data = (SharedData *)shm_ptr;
if ( shared_data < 0 )
if ( shm_ptr < 0 )
{
Error(( "Can't shmat: %s", strerror(errno)));
exit( -1 );
}
trigger_data = (TriggerData *)(shm_ptr + sizeof(SharedData));
shared_data = (SharedData *)shm_ptr;
trigger_data = (TriggerData *)((char *)shared_data + sizeof(SharedData));
struct timeval *shared_timestamps = (struct timeval *)((char *)trigger_data + sizeof(TriggerData));
unsigned char *shared_images = (unsigned char *)((char *)shared_timestamps + (image_buffer_count*sizeof(struct timeval)));
if ( purpose == CAPTURE )
{
@ -184,8 +191,6 @@ void Monitor::Setup()
exit( -1 );
}
struct timeval *shared_timestamps = (struct timeval *)(shm_ptr+sizeof(SharedData)+sizeof(TriggerData));
unsigned char *shared_images = (unsigned char *)(shm_ptr+sizeof(SharedData)+sizeof(TriggerData)+(image_buffer_count*sizeof(struct timeval)));
image_buffer = new Snapshot[image_buffer_count];
for ( int i = 0; i < image_buffer_count; i++ )
{