forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reported by @queequeg
- Loading branch information
Showing
1 changed file
with
18 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
struct destination; // represents what we are connecting to | ||
struct connection; // information needed to use the connection | ||
connection connect(destination*); // open the connection | ||
void disconnect(connection); // close the given connection | ||
void f(destination &d /* other parameters */) | ||
//! @Yue Wang | ||
//! | ||
//! ex12.13 What happens if we excute the following code? | ||
//! | ||
// generate a runtime error : double free | ||
//! | ||
|
||
#include <iostream> | ||
#include <memory> | ||
|
||
int main() | ||
{ | ||
// get a connection; must remember to close it when done | ||
connection c = connect(&d); | ||
// use the connection | ||
// if we forget to call disconnect before exiting f, there will be no way to close c | ||
{ | ||
auto sp = std::make_shared<int>(); | ||
auto p = sp.get(); | ||
delete p; | ||
} | ||
|
||
return 0; | ||
} |