Fix the "Use-after-free" of clang SA.

- Set the pointer to NULL after free it, otherwise the pointer will be accessed again. (since not null)

Signed-off-by: Hung-Weic Chiu <sppsorrg@gmail.com>
This commit is contained in:
Hung-Weic Chiu 2017-04-29 15:02:31 +00:00
parent d8d58e9839
commit 5d6cc38ca3
2 changed files with 4 additions and 1 deletions

View File

@ -209,8 +209,10 @@ msgbuf_clear(struct msgbuf *msgbuf)
{
struct ibuf *buf;
while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL)
while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) {
ibuf_dequeue(msgbuf, buf);
TAILQ_FIRST(&msgbuf->bufs) = NULL;
}
}
int

View File

@ -310,6 +310,7 @@ imsg_get_fd(struct imsgbuf *ibuf)
fd = ifd->fd;
TAILQ_REMOVE(&ibuf->fds, ifd, entry);
free(ifd);
TAILQ_FIRST(&ibuf->fds) = NULL;
return (fd);
}