From cbe7247fff0a395f804b35d2047c3994fa0fd675 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 26 Apr 2005 09:40:36 +0000 Subject: Removed frame memoryleak --- src/decoder.cc | 11 +++++------ src/encoder.cc | 3 +-- src/frame.cc | 9 ++++++++- src/player.cc | 2 +- src/queue.h | 4 ++-- 5 files changed, 17 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/decoder.cc b/src/decoder.cc index 9798b03..cd5806f 100644 --- a/src/decoder.cc +++ b/src/decoder.cc @@ -69,11 +69,13 @@ void Decoder::decode() // Read a dvframe ptr = dv_stream.readFrame(); if(!ptr) return; // No frame read. (Due to firewire error) - Frame *frame = new Frame(ptr, DVPACKAGE_SIZE); + Frame *eframe = new Frame(ptr, DVPACKAGE_SIZE); + Frame *pframe = new Frame(ptr, DVPACKAGE_SIZE); + free(ptr); pthread_mutex_lock(mutex); - encode_queue->push(frame); - player_queue->push(frame); + encode_queue->push(eframe); + player_queue->push(pframe); pthread_mutex_unlock(mutex); sem_post(encode_sem); @@ -84,9 +86,6 @@ void Decoder::decode() user_event.user.data1 = NULL; user_event.user.data2 = NULL; SDL_PushEvent(&user_event); - - // Free framedata. - // free(ptr); } // Kick the others so they wake up with empty queues diff --git a/src/encoder.cc b/src/encoder.cc index d3f4925..08b587d 100644 --- a/src/encoder.cc +++ b/src/encoder.cc @@ -94,8 +94,7 @@ void Encoder::encode() n->sendPackage(&h, frame->data, frame->size); - // free(f->data); - // delete f; + delete frame; } } // pthread_exit(NULL); diff --git a/src/frame.cc b/src/frame.cc index 6a1ba70..4b94fcb 100644 --- a/src/frame.cc +++ b/src/frame.cc @@ -28,13 +28,20 @@ #include "debug.h" +#include +#include + Frame::Frame(unsigned char *d, int sz) { - data = d; + data = (unsigned char *)malloc(sz); + memcpy(data, d, sz); size = sz; } Frame::~Frame() { + free(data); + data = NULL; + size = 0; } diff --git a/src/player.cc b/src/player.cc index bb712f6..8492d42 100644 --- a/src/player.cc +++ b/src/player.cc @@ -164,7 +164,7 @@ void Player::player() SDL_UnlockYUVOverlay(overlay); SDL_DisplayYUVOverlay(overlay, &rect); - // delete frame; + delete frame; break; case SDL_QUIT: diff --git a/src/queue.h b/src/queue.h index 8851c57..7352071 100644 --- a/src/queue.h +++ b/src/queue.h @@ -70,7 +70,7 @@ Queue::~Queue() { if(count != 0) { fprintf(stderr, "Queue not empty (%d)\n", count); - while(T *t = pop()) {}//delete t; + while(T *t = pop()) delete t; } } @@ -84,7 +84,7 @@ void Queue::push(T *t) if(limit && count > 0) { T* tmp = (T*)pop(); - // delete tmp; + delete tmp; } if(!head) { -- cgit v1.2.3