[all-commits] [llvm/llvm-project] 85ec68: [IR] Fix a memory leak if Function::dropAllReferen...

Liqiang TAO via All-commits all-commits at lists.llvm.org
Wed Sep 20 04:17:50 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 85ec68d69bca5ab9b150efc6dacb03c1696ea865
      https://github.com/llvm/llvm-project/commit/85ec68d69bca5ab9b150efc6dacb03c1696ea865
  Author: Liqiang Tao <taolq at outlook.com>
  Date:   2023-09-20 (Wed, 20 Sep 2023)

  Changed paths:
    M llvm/include/llvm/IR/Function.h
    M llvm/lib/IR/Function.cpp

  Log Message:
  -----------
  [IR] Fix a memory leak if Function::dropAllReferences() is followed by setHungoffOperand

This patch fixes a memory leak if Function::dropAllReferences() is followed by setHungoffOperand (e.g. setPersonality)
If NumUserOperands changes from 3 to 0 before calling allocHungoffUselist() to allocate memory,
the memory leaks which are allocated when NumUserOperands is changed from 0 to 3.
e.g.
```
llvm::Function* func = ...;
func->setPersonalityFn(foo);  // (1). call allocHungoffUselist() to allocate memory for uses
func->deleteBody();  // (2). call dropAllReferences(), and it changes NumUserOperands from 3 to 0
// (3). at this point, NumUserOperands is 0, the next line will allocate memory by allocHungoffUselist()
func->setPersonalityFn(bar);  // (4). call allocHungoffUselist(), so memory allocated in (1) leaks.
```

Reviewed By: dexonsmith, MaskRay

Differential Revision: https://reviews.llvm.org/D156618




More information about the All-commits mailing list