fixed some memory leaks and added NULL-checks on mallocs

This commit is contained in:
Ende! 2015-03-16 00:52:36 +01:00
parent d851e83a59
commit f71edda552
3 changed files with 24 additions and 1 deletions

View File

@ -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)

View File

@ -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;

View File

@ -113,6 +113,11 @@ int main()
}
}
VXBaseDataSource_Release(input32);
VXBaseDataSource_Release(input64);
VXBaseInstructionFormatter_Release(formatter);
VXInstructionDecoder_Release(decoder);
getchar();
return 0;
}