Skip to content

Commit

Permalink
[pr17595] Fix a use after free.
Browse files Browse the repository at this point in the history
Destroying the codegen also frees the path of the created object. Copy the
path to a std::string.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192787 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Oct 16, 2013
1 parent d1a4f57 commit 648a2e6
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tools/gold/gold-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,14 @@ static ld_plugin_status all_symbols_read_hook(void) {
exit(0);
}
}
const char *objPath;
if (lto_codegen_compile_to_file(code_gen, &objPath)) {
(*message)(LDPL_ERROR, "Could not produce a combined object file\n");

std::string ObjPath;
{
const char *Temp;
if (lto_codegen_compile_to_file(code_gen, &Temp)) {
(*message)(LDPL_ERROR, "Could not produce a combined object file\n");
}
ObjPath = Temp;
}

lto_codegen_dispose(code_gen);
Expand All @@ -441,9 +446,9 @@ static ld_plugin_status all_symbols_read_hook(void) {
}
}

if ((*add_input_file)(objPath) != LDPS_OK) {
if ((*add_input_file)(ObjPath.c_str()) != LDPS_OK) {
(*message)(LDPL_ERROR, "Unable to add .o file to the link.");
(*message)(LDPL_ERROR, "File left behind in: %s", objPath);
(*message)(LDPL_ERROR, "File left behind in: %s", ObjPath.c_str());
return LDPS_ERR;
}

Expand All @@ -454,7 +459,7 @@ static ld_plugin_status all_symbols_read_hook(void) {
}

if (options::obj_path.empty())
Cleanup.push_back(objPath);
Cleanup.push_back(ObjPath);

return LDPS_OK;
}
Expand Down

0 comments on commit 648a2e6

Please sign in to comment.