From f71edda5528025a91a10f2a5626e93c1d26cf2a9 Mon Sep 17 00:00:00 2001 From: Ende! Date: Mon, 16 Mar 2015 00:52:36 +0100 Subject: [PATCH] fixed some memory leaks and added NULL-checks on mallocs --- Bindings/C/VXInstructionDecoderC.c | 12 +++++++++++- Bindings/C/VXInstructionFormatterC.c | 8 ++++++++ Examples/CBindings/test.c | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Bindings/C/VXInstructionDecoderC.c b/Bindings/C/VXInstructionDecoderC.c index 8541cc2..7c6d862 100644 --- a/Bindings/C/VXInstructionDecoderC.c +++ b/Bindings/C/VXInstructionDecoderC.c @@ -287,6 +287,11 @@ VXBaseDataSourceContext* VXMemoryDataSource_Create( VXMemoryDataSource *thiz = malloc(sizeof(VXMemoryDataSource)); VXBaseDataSourceContext *ctx = malloc(sizeof(VXBaseDataSourceContext)); + if (!thiz || !ctx) + { + return NULL; + } + ctx->d.type = TYPE_MEMORYDATASOURCE; ctx->d.ptr = thiz; @@ -362,6 +367,11 @@ VXInstructionDecoderContext* VXInstructionDecoder_CreateEx( VXInstructionDecoder *thiz = malloc(sizeof(VXInstructionDecoder)); VXInstructionDecoderContext *ctx = malloc(sizeof(VXInstructionDecoderContext)); + if (!thiz || !ctx) + { + return NULL; + } + ctx->d.ptr = thiz; ctx->d.type = TYPE_INSTRUCTIONDECODER; @@ -1590,7 +1600,7 @@ static bool VXInstructionDecoder_DecodeOpcode(VXInstructionDecoderContext *ctx, { if (info->operand[i].type != OPTYPE_NONE) { - info->operand[i - 1].access_mode = OPACCESSMODE_READ; + info->operand[i].access_mode = OPACCESSMODE_READ; } } if (info->operand[0].type != OPTYPE_NONE) diff --git a/Bindings/C/VXInstructionFormatterC.c b/Bindings/C/VXInstructionFormatterC.c index 64db11f..cd81a15 100644 --- a/Bindings/C/VXInstructionFormatterC.c +++ b/Bindings/C/VXInstructionFormatterC.c @@ -193,6 +193,11 @@ VXBaseSymbolResolverContext* VXCustomSymbolResolver_Create( VXCustomSymbolResolver *thiz = malloc(sizeof(VXCustomSymbolResolver)); VXBaseSymbolResolverContext *ctx = malloc(sizeof(VXBaseSymbolResolverContext)); + if (!thiz || !ctx) + { + return NULL; + } + ctx->d.type = TYPE_CUSTOMSYMBOLRESOLVER; ctx->d.ptr = thiz; @@ -676,6 +681,9 @@ VXBaseInstructionFormatterContext* VXIntelInstructionFormatter_CreateEx( VXIntelInstructionFormatter *thiz = malloc(sizeof(VXIntelInstructionFormatter)); VXBaseInstructionFormatterContext *ctx = malloc(sizeof(VXBaseInstructionFormatterContext)); + if (!thiz || !ctx) + return NULL; + ctx->d.type = TYPE_INTELINSTRUCTIONFORMATTER; ctx->d.ptr = thiz; diff --git a/Examples/CBindings/test.c b/Examples/CBindings/test.c index 3cfa534..ae68857 100644 --- a/Examples/CBindings/test.c +++ b/Examples/CBindings/test.c @@ -113,6 +113,11 @@ int main() } } + VXBaseDataSource_Release(input32); + VXBaseDataSource_Release(input64); + VXBaseInstructionFormatter_Release(formatter); + VXInstructionDecoder_Release(decoder); + getchar(); return 0; } \ No newline at end of file