diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-10-16 12:47:04 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-10-16 12:47:04 +0000 |
commit | 648a2e6714885e9b3d2a4f380434fe44ef2c4b5b (patch) | |
tree | c717d617ac4bb03f8b807543160e74ac2d3ea5c1 /tools/gold | |
parent | d1a4f579bf45aec933c79292b6b9663581438738 (diff) | |
download | external_llvm-648a2e6714885e9b3d2a4f380434fe44ef2c4b5b.zip external_llvm-648a2e6714885e9b3d2a4f380434fe44ef2c4b5b.tar.gz external_llvm-648a2e6714885e9b3d2a4f380434fe44ef2c4b5b.tar.bz2 |
[pr17595] Fix a use after free.
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
Diffstat (limited to 'tools/gold')
-rw-r--r-- | tools/gold/gold-plugin.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 119631c..8261739 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -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); @@ -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; } @@ -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; } |