Global pointer gplist is used to record hazard pointer array once it's allocated. This can avoid allocating and freeing hazptr array each time function hazptr_scan() is invoked. This patch fixes a memory leak bug and helps achieve the design goal. Signed-off-by: Junchang Wang <junchangwang@xxxxxxxxx> --- CodeSamples/defer/hazptr.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CodeSamples/defer/hazptr.c b/CodeSamples/defer/hazptr.c index 91df310..061ca2c 100644 --- a/CodeSamples/defer/hazptr.c +++ b/CodeSamples/defer/hazptr.c @@ -53,6 +53,9 @@ void hazptr_thread_exit(void) hazptr_scan(); poll(NULL, 0, 1); } + + if (gplist != NULL) + free(gplist); } void hazptr_reinitialize() @@ -103,6 +106,7 @@ void hazptr_scan() fprintf(stderr, "hazptr_scan: out of memory\n"); exit(EXIT_FAILURE); } + gplist = plist; } /* -- 2.7.4