Skip to content

Commit

Permalink
Replace stack memory bug with memory leak.
Browse files Browse the repository at this point in the history
Using a std::string::c_str() pointer after the destruction of its
instance is an error.  For now, we "fix" this problem by allocating
heap memory.  This should eventually be replaced by a static table.
  • Loading branch information
rchyena committed Sep 23, 2017
1 parent a865b74 commit 8feba97
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion instructionAPI/src/InstructionDecoder-aarch32.C
Expand Up @@ -180,8 +180,10 @@ InstructionDecoder_aarch32::mainDecode(void)
std::string mnemonic(insnInfo->mnemonic);

mnemonic += insnSuffix[get_condition_field(rawInsn)];
char* mnemonicCopy = (char*)malloc(mnemonic.length() + 1);
strcpy(mnemonicCopy, mnemonic.c_str());
decodedInsn = makeInstruction(insnInfo->op,
mnemonic.c_str(),
mnemonicCopy,
4,
rawPtr);
decodedInsn->arch_decoded_from = Arch_aarch32;
Expand Down

0 comments on commit 8feba97

Please sign in to comment.