Skip to content

Commit 86b59b6

Browse files
committed
dpl: fix small memory leaks
Signed-off-by: Matt Liberty <[email protected]>
1 parent 6354e32 commit 86b59b6

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

src/dpl/include/dpl/Opendp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Opendp
147147

148148
using MasterByImplant = std::map<odb::dbTechLayer*, dbMasterSeq>;
149149

150-
using YCoordToGap = std::map<DbuY, std::vector<GapInfo*>>;
150+
using YCoordToGap = std::map<DbuY, std::vector<std::unique_ptr<GapInfo>>>;
151151

152152
friend class OpendpTest_IsPlaced_Test;
153153
friend class Graphics;
@@ -290,7 +290,7 @@ class Opendp
290290
void insertDecapInPos(odb::dbMaster* master,
291291
const DbuX& pos_x,
292292
const DbuY& pos_y);
293-
void insertDecapInRow(const std::vector<GapInfo*>& gaps,
293+
void insertDecapInRow(const std::vector<std::unique_ptr<GapInfo>>& gaps,
294294
DbuY gap_y,
295295
DbuX irdrop_x,
296296
DbuY irdrop_y,
@@ -333,7 +333,7 @@ class Opendp
333333
bool have_fillers_ = false;
334334

335335
// Decap placement.
336-
std::vector<DecapCell*> decap_masters_;
336+
std::vector<std::unique_ptr<DecapCell>> decap_masters_;
337337
int decap_count_ = 0;
338338
YCoordToGap gaps_;
339339

src/dpl/src/DecapPlacement.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <algorithm>
55
#include <map>
6+
#include <memory>
67
#include <string>
78
#include <vector>
89

@@ -83,7 +84,8 @@ void Opendp::prepareDecapAndGaps()
8384
// Sort decaps cells in descending order
8485
std::sort(decap_masters_.begin(),
8586
decap_masters_.end(),
86-
[](const DecapCell* decap1, const DecapCell* decap2) {
87+
[](const std::unique_ptr<DecapCell>& decap1,
88+
const std::unique_ptr<DecapCell>& decap2) {
8789
return decap1->capacitance > decap2->capacitance;
8890
});
8991

@@ -92,11 +94,11 @@ void Opendp::prepareDecapAndGaps()
9294
int gaps_count = 0;
9395
// Sort each gap vector for X position
9496
for (auto& it : gaps_) {
95-
std::sort(it.second.begin(),
96-
it.second.end(),
97-
[](const GapInfo* gap1, const GapInfo* gap2) {
98-
return gap1->x < gap2->x;
99-
});
97+
std::sort(
98+
it.second.begin(),
99+
it.second.end(),
100+
[](const std::unique_ptr<GapInfo>& gap1,
101+
const std::unique_ptr<GapInfo>& gap2) { return gap1->x < gap2->x; });
100102
gaps_count += it.second.size();
101103
}
102104

@@ -166,19 +168,20 @@ void Opendp::insertDecapCells(const double target, IRDropByPoint& psm_ir_drops)
166168
total_cap);
167169
}
168170

169-
void Opendp::insertDecapInRow(const std::vector<GapInfo*>& gaps,
171+
void Opendp::insertDecapInRow(const std::vector<std::unique_ptr<GapInfo>>& gaps,
170172
const DbuY gap_y,
171173
const DbuX irdrop_x,
172174
const DbuY irdrop_y,
173175
double& total,
174176
const double& target)
175177
{
176178
// Find gap in same row and x near the ir drop
177-
auto find_gap = std::lower_bound(
178-
gaps.begin(),
179-
gaps.end(),
180-
irdrop_x,
181-
[](const GapInfo* elem, const DbuX& value) { return elem->x < value; });
179+
auto find_gap
180+
= std::lower_bound(gaps.begin(),
181+
gaps.end(),
182+
irdrop_x,
183+
[](const std::unique_ptr<GapInfo>& elem,
184+
const DbuX& value) { return elem->x < value; });
182185
// if this row has free gap with x <= xpoint <= x + width
183186
if (find_gap != gaps.end()
184187
&& ((*find_gap)->x + (*find_gap)->width) >= irdrop_x

src/dpl/src/Opendp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "dpl/OptMirror.h"
1919
#include "graphics/DplObserver.h"
2020
#include "infrastructure/Coordinates.h"
21+
#include "infrastructure/DecapObjects.h"
2122
#include "infrastructure/Grid.h"
2223
#include "infrastructure/Objects.h"
2324
#include "infrastructure/Padding.h"

0 commit comments

Comments
 (0)