Permalink
Browse files

Memory leaks found by valgrind:

- SubRenderer was recreated and leaked on every Preflight call
(since multiple preflights can happen to the same component)
- AVCodecParser was never closed by FFusion
- CXXSubSerializer could never free itself
- an AVCodecContext could leak if the parser couldn't open

Found by GCC warnings:
- Many harmless(?) missing function prototypes
- "storage->movieLoadState ==" should be =

- Reroll an uselessly unrolled loop
- Rename freeFFusionParser to match the other function style
(this doesn't even begin to clean anything up)


git-svn-id: https://svn.perian.org/trunk@1086 621663c8-3916-0410-8f58-edc14a8543d5
  • Loading branch information...
astrange
astrange committed Jun 25, 2009
1 parent d1ef4ad commit dd5eb35eb4b166035ef81258657c54157d5d5ccb
Showing with 39 additions and 39 deletions.
  1. +2 −1 FFusionCodec.c
  2. +1 −0 FrameBuffer.h
  3. +4 −7 Subtitles/SubATSUIRenderer.m
  4. +2 −2 Subtitles/SubContext.m
  5. +1 −0 Subtitles/SubImport.h
  6. +6 −6 Subtitles/SubImport.mm
  7. +2 −5 TextSubCodec.c
  8. +2 −0 VobSubCodec.c
  9. +16 −16 bitstream_info.c
  10. +1 −0 bitstream_info.h
  11. +2 −2 ff_MovieImport.c
View
@@ -31,6 +31,7 @@
#include <Carbon/Carbon.h>
#include <QuickTime/QuickTime.h>
#include <Accelerate/Accelerate.h>
#include <sys/sysctl.h>
#include "FFusionCodec.h"
#include "EI_Image.h"
@@ -413,7 +414,7 @@ pascal ComponentResult FFusionCodecClose(FFusionGlobals glob, ComponentInstance
if (glob->begin.parser)
{
freeFFusionParser(glob->begin.parser);
ffusionParserFree(glob->begin.parser);
}
if (glob->pixelTypes)
View
@@ -102,6 +102,7 @@ FrameData *FFusionDataAppend(FFusionData *data, uint8_t *buffer, int dataSize, i
*/
void FFusionDataSetUnparsed(FFusionData *data, uint8_t *buffer, int bufferSize);
void FFusionDataReadUnparsed(FFusionData *data);
/*!
* @brief Mark a frame as no longer needed
@@ -252,7 +252,7 @@ -(SubATSUIRenderer*)initWithVideoWidth:(float)width videoHeight:(float)height;
videoHeight = height;
UCCreateTextBreakLocator(NULL, 0, kUCTextBreakLineMask, &breakLocator);
[[SubContext alloc] initWithNonSSAType:kSubTypeSRT delegate:self];
context = [[SubContext alloc] initWithNonSSAType:kSubTypeSRT delegate:self];
}
return self;
@@ -276,7 +276,7 @@ -(SubATSUIRenderer*)initWithSSAHeader:(NSString*)header videoWidth:(float)width
srgbCSpace = GetSRGBColorSpace();
UCCreateTextBreakLocator(NULL, 0, kUCTextBreakLineMask, &breakLocator);
[[SubContext alloc] initWithHeaders:headers styles:styles delegate:self];
context = [[SubContext alloc] initWithHeaders:headers styles:styles delegate:self];
}
return self;
@@ -302,9 +302,8 @@ -(void)finalize
-(void)completedHeaderParsing:(SubContext*)sc
{
context = sc;
screenScaleX = videoWidth / context->resX;
screenScaleY = videoHeight / context->resY;
screenScaleX = videoWidth / sc->resX;
screenScaleY = videoHeight / sc->resY;
}
-(float)aspectRatio
@@ -1185,7 +1184,6 @@ void SubRenderPacket(SubtitleRendererPtr s, CGContextRef c, CFStringRef str, int
void SubPrerollFromHeader(char *header, int headerLen)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SubtitleRendererPtr s = headerLen ? SubInitForSSA(header, headerLen, 640, 480)
: SubInitNonSSA(640, 480);
/*
@@ -1212,7 +1210,6 @@ void SubPrerollFromHeader(char *header, int headerLen)
*/
SubDisposeRenderer(s);
[pool release];
}
void SubDisposeRenderer(SubtitleRendererPtr s)
View
@@ -267,7 +267,7 @@ -(SubContext*)initWithHeaders:(NSDictionary *)headers_ styles:(NSArray *)styles_
[defaultStyle retain];
}
return self;
}
@@ -284,7 +284,7 @@ -(SubContext*)initWithNonSSAType:(UInt8)type delegate:(SubRenderer*)delegate
defaultStyle = [[SubStyle defaultStyleWithDelegate:delegate] retain];
}
return self;
}
View
@@ -109,6 +109,7 @@ extern NSString *LoadSSAFromPath(NSString *path, SubSerializer *ss);
class CXXSubSerializer
{
__strong void *priv;
int retainCount;
public:
CXXSubSerializer();
View
@@ -1432,6 +1432,7 @@ - (void)addSampleTime:(long)time offset:(long)offset
{
priv = [[SubSerializer alloc] init];
CFRetain(priv);
retainCount = 1;
}
CXXSubSerializer::~CXXSubSerializer()
@@ -1471,17 +1472,16 @@ - (void)addSampleTime:(long)time offset:(long)offset
}
void CXXSubSerializer::release()
{
SubSerializer *s = (SubSerializer*)priv;
int r = [s retainCount];
{
retainCount--;
if (r == 1) delete this;
else [s release];
if (!retainCount)
delete this;
}
void CXXSubSerializer::retain()
{
[(SubSerializer*)priv retain];
retainCount++;
}
bool CXXSubSerializer::empty()
View
@@ -116,6 +116,7 @@ pascal ComponentResult TextSubCodecOpen(TextSubGlobals glob, ComponentInstance s
glob->drawBandUPP = NULL;
glob->ssa = NULL;
glob->colorSpace = NULL;
glob->translateSRT = true;
// Open and target an instance of the base decompressor as we delegate
// most of our calls to the base decompressor instance
@@ -247,11 +248,7 @@ pascal ComponentResult TextSubCodecPreflight(TextSubGlobals glob, CodecDecompres
capabilities->extendHeight = 0;
capabilities->flags |= codecCanAsync | codecCanAsyncWhen | codecCanScale;
capabilities->flags2 |= codecDrawsHigherQualityScaled;
glob->colorSpace = NULL;
glob->translateSRT = true;
glob->ssa = NULL;
capabilities->flags2 |= codecDrawsHigherQualityScaled;
if (!glob->ssa) {
if ((**p->imageDescription).cType == kSubFormatSSA) {
View
@@ -23,6 +23,7 @@
#include <QuickTime/QuickTime.h>
#include "VobSubCodec.h"
#include "Codecprintf.h"
#include "CommonUtils.h"
#include <zlib.h>
#include "avcodec.h"
#include "intreadwrite.h"
@@ -84,6 +85,7 @@ typedef struct {
int ExtractVobSubPacket(UInt8 *dest, UInt8 *framedSrc, int srcSize, int *usedSrcBytes);
static ComponentResult ReadPacketControls(UInt8 *packet, UInt32 palette[16], PacketControlData *controlDataOut);
extern void initLib();
extern void init_FFmpeg();
ComponentResult VobSubCodecOpen(VobSubCodecGlobals glob, ComponentInstance self)
{
View
@@ -35,6 +35,8 @@
#include "mpegvideo.h"
#include "parser.h"
#include "golomb.h"
#include "mpeg4video_parser.h"
#include "Codecprintf.h"
#include "CodecIDs.h"
@@ -867,18 +869,19 @@ void initFFusionParsers()
}
}
void freeFFusionParser(FFusionParserContext *parser)
void ffusionParserFree(FFusionParserContext *parser)
{
AVCodecParser *avparse = parser->parserStructure->avparse;
if(parser->pc)
{
if(parser->pc->priv_data)
av_free(parser->pc->priv_data);
if (avparse->parser_close)
avparse->parser_close(parser->pc);
av_free(parser->pc->priv_data);
av_free(parser->pc);
}
if(parser->avctx)
av_free(parser->avctx);
if(parser->internalContext)
av_free(parser->internalContext);
av_free(parser->avctx);
av_free(parser->internalContext);
free(parser);
}
@@ -887,8 +890,7 @@ FFusionParserContext *ffusionParserInit(int codec_id)
AVCodecParserContext *s;
AVCodecParser *parser;
FFusionParser *ffParser;
int ret;
struct AVCodecContext *ctx = avcodec_alloc_context();
int ret, i;
if(codec_id == CODEC_ID_NONE)
return NULL;
@@ -897,12 +899,10 @@ FFusionParserContext *ffusionParserInit(int codec_id)
for(ffParser = ffusionFirstParser; ffParser != NULL; ffParser = ffParser->next) {
parser = ffParser->avparse;
if (parser->codec_ids[0] == codec_id ||
parser->codec_ids[1] == codec_id ||
parser->codec_ids[2] == codec_id ||
parser->codec_ids[3] == codec_id ||
parser->codec_ids[4] == codec_id)
goto found;
for (i = 0; i < 5; i++)
if (parser->codec_ids[i] == codec_id)
goto found;
}
return NULL;
found:
@@ -927,7 +927,7 @@ FFusionParserContext *ffusionParserInit(int codec_id)
s->flags |= PARSER_FLAG_COMPLETE_FRAMES;
FFusionParserContext *parserContext = malloc(sizeof(FFusionParserContext));
parserContext->avctx = ctx;
parserContext->avctx = avcodec_alloc_context();
parserContext->pc = s;
parserContext->parserStructure = ffParser;
if(ffParser->internalContextSize)
View
@@ -58,6 +58,7 @@ typedef enum {
void initFFusionParsers();
FFusionParserContext *ffusionParserInit(int codec_id);
void ffusionParserFree(FFusionParserContext *parser);
int ffusionParseExtraData(FFusionParserContext *parser, const uint8_t *buf, int buf_size);
int ffusionParse(FFusionParserContext *parser, const uint8_t *buf, int buf_size, int *out_buf_size, int *type, int *skippable);
void ffusionLogDebugInfo(FFusionParserContext *parser, FILE *log);
View
@@ -555,9 +555,9 @@ ComponentResult FFAvi_MovieImportDataRef(ff_global_ptr storage, Handle dataRef,
bail:
if(result == noErr)
storage->movieLoadState == kMovieLoadStateLoaded;
storage->movieLoadState = kMovieLoadStateLoaded;
else
storage->movieLoadState == kMovieLoadStateError;
storage->movieLoadState = kMovieLoadStateError;
if (result == -1)
result = invalidMovie; // a bit better error message

0 comments on commit dd5eb35

Please sign in to comment.