From b93ddf848b7c498dcc9af72705791b4f63c25b63 Mon Sep 17 00:00:00 2001 From: Ende! Date: Thu, 19 Mar 2015 19:30:25 +0100 Subject: [PATCH] fixed potential memory leak --- .../VXInstructionDecoder.c | 32 +++++++++++++++++++ .../VXInstructionFormatter.c | 20 ++++++++++++ 2 files changed, 52 insertions(+) diff --git a/VerteronDisassemblerEngine/VXInstructionDecoder.c b/VerteronDisassemblerEngine/VXInstructionDecoder.c index d9aa5c1..1296aee 100644 --- a/VerteronDisassemblerEngine/VXInstructionDecoder.c +++ b/VerteronDisassemblerEngine/VXInstructionDecoder.c @@ -526,6 +526,15 @@ VXBaseDataSourceContext* VXMemoryDataSource_Create( if (!thiz || !ctx) { + if (thiz) + { + free(thiz); + } + if (ctx) + { + free(ctx); + } + return NULL; } @@ -614,6 +623,20 @@ VXBaseDataSourceContext* VXCustomDataSource_Create( VXCustomDataSource *thiz = malloc(sizeof(VXCustomDataSource)); VXBaseDataSourceContext *ctx = malloc(sizeof(VXBaseDataSourceContext)); + if (!thiz || !ctx) + { + if (thiz) + { + free(thiz); + } + if (ctx) + { + free(ctx); + } + + return NULL; + } + ctx->d.type = TYPE_CUSTOMDATASOURCE; ctx->d.ptr = thiz; @@ -656,6 +679,15 @@ VXInstructionDecoderContext* VXInstructionDecoder_CreateEx(VXBaseDataSourceConte if (!thiz || !ctx) { + if (thiz) + { + free(thiz); + } + if (ctx) + { + free(ctx); + } + return NULL; } diff --git a/VerteronDisassemblerEngine/VXInstructionFormatter.c b/VerteronDisassemblerEngine/VXInstructionFormatter.c index 84113dd..4613095 100644 --- a/VerteronDisassemblerEngine/VXInstructionFormatter.c +++ b/VerteronDisassemblerEngine/VXInstructionFormatter.c @@ -325,6 +325,15 @@ VXBaseSymbolResolverContext* VXCustomSymbolResolver_Create( if (!thiz || !ctx) { + if (thiz) + { + free(thiz); + } + if (ctx) + { + free(ctx); + } + return NULL; } @@ -807,7 +816,18 @@ VXBaseInstructionFormatterContext* VXIntelInstructionFormatter_CreateEx( VXBaseInstructionFormatterContext *ctx = malloc(sizeof(VXBaseInstructionFormatterContext)); if (!thiz || !ctx) + { + if (thiz) + { + free(thiz); + } + if (ctx) + { + free(ctx); + } + return NULL; + } ctx->d.type = TYPE_INTELINSTRUCTIONFORMATTER; ctx->d.ptr = thiz;