Fix a resource leak in an error case in camdd_buf_sg_create().

Submitted by:	Coverity
CID:		1341622
MFC after:	3 days
Sponsored by:	Spectra Logic
This commit is contained in:
Kenneth D. Merry 2017-08-23 17:52:49 +00:00
parent c72fadf8f0
commit 2d73f7e208
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=322819

View file

@ -824,6 +824,7 @@ camdd_buf_sg_create(struct camdd_buf *buf, int iovec, uint32_t sector_size,
struct camdd_buf_data *data;
uint8_t *extra_buf = NULL;
size_t extra_buf_len = 0;
int extra_buf_attached = 0;
int i, retval = 0;
data = &buf->buf_type_spec.data;
@ -913,6 +914,7 @@ camdd_buf_sg_create(struct camdd_buf *buf, int iovec, uint32_t sector_size,
data->iovec[i].iov_base = extra_buf;
data->iovec[i].iov_len = extra_buf_len;
}
extra_buf_attached = 1;
i++;
}
if ((tmp_buf != NULL) || (i != data->sg_count)) {
@ -926,6 +928,14 @@ camdd_buf_sg_create(struct camdd_buf *buf, int iovec, uint32_t sector_size,
if (retval == 0) {
*num_sectors_used = (data->fill_len + extra_buf_len) /
sector_size;
} else if (extra_buf_attached == 0) {
/*
* If extra_buf isn't attached yet, we need to free it
* to avoid leaking.
*/
free(extra_buf);
data->extra_buf = 0;
data->sg_count--;
}
return (retval);
}