Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointer to invalid memory kept #1820

Closed
llvmbot opened this issue May 27, 2007 · 5 comments
Closed

Pointer to invalid memory kept #1820

llvmbot opened this issue May 27, 2007 · 5 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla compile-fail Use [accepts-invalid] and [rejects-valid] instead llvm-tools All llvm tools that do not have corresponding tag

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented May 27, 2007

Bugzilla Link 1448
Resolution FIXED
Resolved on Feb 22, 2010 12:41
Version 2.0
OS All
Reporter LLVM Bugzilla Contributor

Extended Description

In tools/llvm-ld/llvm-ld.cpp, around line 353, a 'const char *' to a temporary
std::string is being stored, with the string going out of scope right after,
making that pointer invalid. Snippet:

std::string lib_name = "-l" + LinkItems[index].first;
args.push_back(lib_name.c_str());
<end of scope>

I originally reported this problem on the llvm-commit list, because I was told
to do so, but maybe I should have opened a bug report anyway. See [1] and its
follow-ups for a simple fix.

Funnily, in my particular case, things still worked fine as long as I only had
one -l option. But with several such option, all pointers in 'args' pointed to
the exact same memory location, still containing the last library name
processed and gcc got called like "gcc -llib -llib -llib -llib".

[1] http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070430/
048734.html

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 27, 2007

assigned to @lattner

@lattner
Copy link
Collaborator

lattner commented May 27, 2007

This is certainly a bug, but the attached patch doesn't fix it completely, because the vector could cause
reallocation of the string data.

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 27, 2007

Yes, that's been mentioned too[1]. std::list would be one way to go.

[1] http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070430/
048862.html

@nlewycky
Copy link
Contributor

fix using strdup
Here's a potential fix based on strdup.

Note that this could leak if an exception is thrown, though I don't think
that's possible. It's too bad that vector<auto_ptr> is illegal code.

@lattner
Copy link
Collaborator

lattner commented Jun 19, 2007

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla compile-fail Use [accepts-invalid] and [rejects-valid] instead llvm-tools All llvm tools that do not have corresponding tag
Projects
None yet
Development

No branches or pull requests

3 participants