Skip to content

Unexpected pointer wrapping when manually inserting LLVM modules #17

@MarcelHB

Description

@MarcelHB

Hallo again,

There is something I noticed. I made my project a standalone Phasar tool, and I preprocess LLVM IR code by making it feed to llvm::parseIRFile first, then doing some transformations, and then passing it to psr::ProjectIRDB#insert_module. For the next run, I was greeted by a double free error.

The cause is located here: https://github.com/secure-software-engineering/phasar/blob/master/lib/DB/ProjectIRDB.cpp#L706

I originally created the llvm::LLVMContext as a stack variable in my main and used that for parsing. So I suggest to change the signature of that method to something like:

void ProjectIRDB::insertModule(
  std::unique_ptr<llvm::Module> M, 
  std::unique_ptr<llvm::LLVMContext> C
);

So that I can create and move the required context pointer explicitly. For now, I do:

// Phasar cleans this up.
auto context = new llvm::LLVMContext;

That's Ok, but secretly wrapping M->getContext() into a unique pointer is a sneaky move. 😉

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions