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

Disk Info is not Thread-Safe #63

Closed
cetra3 opened this issue Jun 1, 2020 · 0 comments · Fixed by #84
Closed

Disk Info is not Thread-Safe #63

cetra3 opened this issue Jun 1, 2020 · 0 comments · Fixed by #84

Comments

@cetra3
Copy link

cetra3 commented Jun 1, 2020

I've seen a few segmentation faults when running disk_info() on linux.

If you call disk_info() from multiple threads at once this can core dump:

#5  0x00005585db2e28cc in DFcleanup () at c/linux.c:167
#6  0x00005585db2e265f in get_disk_info () at c/linux.c:117
#7  0x00005585db2cee4a in sys_info::disk_info () at /home/cetra/.cargo/registry/src/github.com-1ecc6299db9ec823/sys-info-0.6.0/lib.rs:494

There is a global DFhashvector:

static struct nlist *DFhashvector[DFHASHSIZE];

Which, if two threads are calling disk_info() the DFCleanup() call at the end of the get_disk_info() function will both try and free at the same time:

sys-info-rs/c/linux.c

Lines 159 to 172 in a5d126d

void DFcleanup()
{
struct nlist *np, *next;
int i;
for (i=0; i<DFHASHSIZE; i++) {
/* Non-standard for loop. Note the last clause happens at the end of the loop. */
for (np = DFhashvector[i]; np; np=next) {
next=np->next;
free(np->name);
free(np);
}
DFhashvector[i] = 0;
}
}

This results in segfaults & also double frees

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant