-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_safe_free.cpp
More file actions
30 lines (25 loc) · 782 Bytes
/
test_safe_free.cpp
File metadata and controls
30 lines (25 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*****************************************************************//**
* \file test_safe_free.cpp
* \brief Demonstration of library code in ".\util\safe_free.hpp"
*
* To compile and run this file on Windows:
* $ g++ -o test_safe_free.exe .\test_safe_free.cpp -std=c++11
* $ .\test_safe_free.exe
*
* \author Xuhua Huang
* \date September 2022
*********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "safe_free.hpp"
int main(void) {
int* pi;
pi = (int*)malloc(sizeof(int));
*pi = 5;
printf("Before: %p.\n", pi);
util::pointer::safe_free((void**)&(pi));
printf("After: %p.\n", pi);
util::pointer::safe_free((void**)&(pi));
system("pause");
return EXIT_SUCCESS;
}