Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid memory operations on calling initialize/destroy functions repetitively #94

Closed
wusyong opened this issue Jan 31, 2019 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@wusyong
Copy link

wusyong commented Jan 31, 2019

There's a bug when utilizing dcurl after first time. Calling dcurl_destroy in second time would yield double free error:

[dcurl] Implementation CPU (Intel SSE) is initialized successfully
test-dcurl(34354,0x1115395c0) malloc: *** error for object 0x7f9ed4d00000: pointer being freed was not allocated
test-dcurl(34354,0x1115395c0) malloc: *** set a breakpoint in malloc_error_break to debug
/bin/sh: line 1: 34354 Abort trap: 6           ./build/test-dcurl
make: *** [build/test-dcurl.done] Error 134

Step to reproduce:
Put another dcurl_init and dcurl_destroy in test_dcurl test, then simply make check.

@jserv
Copy link
Member

jserv commented Jan 31, 2019

I rebuilt dcurl with AddressSanitizer, and make check aborted with the following messages:

==52602==ERROR: LeakSanitizer: detected memory leaks
...
SUMMARY: AddressSanitizer: 37866102 byte(s) leaked in 663 allocation(s).

@marktwtn marktwtn added the bug Something isn't working label Jan 31, 2019
@marktwtn marktwtn changed the title Double free error when initialize/free repetitively Bug: Encounter memory free error while calling initialize/destroy functions repetitively Jan 31, 2019
@marktwtn
Copy link
Collaborator

marktwtn commented Feb 1, 2019

In dcurl, we maintain a double-linked list with nodes representing different hardware architectures.

dcurl_init() should add the nodes into the list and dcurl_destroy() should remove the nodes from the list.
However, the current implementation of dcurl_destroy() does not call the corresponding function to remove it.

As calling dcurl_init() and dcurl_destroy() repeatedly without removing the nodes, the list would behave unexpectedly.

In this issue, the unexpected behaviour makes dcurl_destroy() call the function destroyImplContext() more times than it should have, which causes the memory free error.

@jserv jserv changed the title Bug: Encounter memory free error while calling initialize/destroy functions repetitively Invalid memory operations on calling initialize/destroy functions repetitively Feb 1, 2019
marktwtn added a commit to marktwtn/dcurl that referenced this issue Feb 1, 2019
The memory double free error occurs if we initialize and destroy dcurl repeatedly.
dcurl maintains a list of nodes for different hardwares.
The error is caused by forgetting to remove the nodes from the list.
To fix it, add the corresponding function list_del() in dcurl_destroy().

Besides fixing the error, one of the testcases is modified
to repeatedly test the initialization and destruction of dcurl N times.
The value of N equals to 5.

Close DLTcollab#94.
@jserv jserv closed this as completed in #96 Feb 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants