mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-14 11:08:06 +00:00
afl-sharedmem.c: fix leaks on error paths (SysV shared memory)
This commit is contained in:
@ -239,7 +239,10 @@ u8 *afl_shm_init(sharedmem_t *shm, size_t map_size,
|
||||
shm->cmplog_shm_id = shmget(IPC_PRIVATE, sizeof(struct cmp_map),
|
||||
IPC_CREAT | IPC_EXCL | 0600);
|
||||
|
||||
if (shm->cmplog_shm_id < 0) { PFATAL("shmget() failed"); }
|
||||
if (shm->cmplog_shm_id < 0) {
|
||||
shmctl(shm->shm_id, IPC_RMID, NULL); // do not leak shmem
|
||||
PFATAL("shmget() failed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -266,7 +269,13 @@ u8 *afl_shm_init(sharedmem_t *shm, size_t map_size,
|
||||
|
||||
shm->map = shmat(shm->shm_id, NULL, 0);
|
||||
|
||||
if (shm->map == (void *)-1 || !shm->map) { PFATAL("shmat() failed"); }
|
||||
if (shm->map == (void *)-1 || !shm->map) {
|
||||
shmctl(shm->shm_id, IPC_RMID, NULL); // do not leak shmem
|
||||
if (shm->cmplog_mode) {
|
||||
shmctl(shm->cmplog_shm_id, IPC_RMID, NULL); // do not leak shmem
|
||||
}
|
||||
PFATAL("shmat() failed");
|
||||
}
|
||||
|
||||
if (shm->cmplog_mode) {
|
||||
|
||||
@ -274,6 +283,10 @@ u8 *afl_shm_init(sharedmem_t *shm, size_t map_size,
|
||||
|
||||
if (shm->cmp_map == (void *)-1 || !shm->cmp_map) {
|
||||
|
||||
shmctl(shm->shm_id, IPC_RMID, NULL); // do not leak shmem
|
||||
if (shm->cmplog_mode) {
|
||||
shmctl(shm->cmplog_shm_id, IPC_RMID, NULL); // do not leak shmem
|
||||
}
|
||||
PFATAL("shmat() failed");
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user