Skip to content

Commit d52210d

Browse files
committed
C++: Improve the example for cpp/return-stack-allocated-memory.
1 parent 3c70583 commit d52210d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
Record* fixRecord(Record* r) {
2-
Record myRecord = *r;
3-
delete r;
1+
Record *mkRecord(int value) {
2+
Record myRecord(value);
43

5-
myRecord.fix();
6-
return &myRecord; //returns reference to myRecord, which is a stack-allocated object
7-
}
4+
return &myRecord; // BAD: return a pointer to `myRecord`, which is a stack-allocated object
5+
}

0 commit comments

Comments
 (0)