From 9e03d55a8cf3e68675ed281c31a5a077bd586a33 Mon Sep 17 00:00:00 2001 From: stan Date: Tue, 22 Nov 2005 10:39:51 +0000 Subject: [PATCH] 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 --- src/zm_monitor.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 5631db834..062cae6a8 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -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++ ) {