Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F160887190
D57887.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D57887.diff
View Options
diff --git a/usr.sbin/bhyve/block_if.c b/usr.sbin/bhyve/block_if.c
--- a/usr.sbin/bhyve/block_if.c
+++ b/usr.sbin/bhyve/block_if.c
@@ -479,7 +479,7 @@
char name[MAXPATHLEN];
const char *path, *pssval, *ssval, *bootindex_val;
char *cp;
- struct blockif_ctxt *bc;
+ struct blockif_ctxt *bc = NULL;
struct stat sbuf;
struct diocgattr_arg arg;
off_t size, psectsz, psectoff;
@@ -650,10 +650,17 @@
bc->bc_sectsz = sectsz;
bc->bc_psectsz = psectsz;
bc->bc_psectoff = psectoff;
- pthread_mutex_init(&bc->bc_mtx, NULL);
- pthread_cond_init(&bc->bc_cond, NULL);
+ bc->bc_mtx = NULL;
+ bc->bc_cond = bc->bc_work_done_cond = NULL;
+ for (i = 0; i < BLOCKIF_NUMTHR; i++)
+ bc->bc_btid[i] = NULL;
+ if (pthread_mutex_init(&bc->bc_mtx, NULL))
+ goto err;
+ if (pthread_cond_init(&bc->bc_cond, NULL))
+ goto err;
bc->bc_paused = 0;
- pthread_cond_init(&bc->bc_work_done_cond, NULL);
+ if (pthread_cond_init(&bc->bc_work_done_cond, NULL))
+ goto err;
TAILQ_INIT(&bc->bc_freeq);
TAILQ_INIT(&bc->bc_pendq);
TAILQ_INIT(&bc->bc_busyq);
@@ -664,13 +671,34 @@
}
for (i = 0; i < BLOCKIF_NUMTHR; i++) {
- pthread_create(&bc->bc_btid[i], NULL, blockif_thr, bc);
+ if (pthread_create(&bc->bc_btid[i], NULL, blockif_thr, bc)) {
+ bc->bc_btid[i] = NULL;
+ goto err;
+ }
snprintf(tname, sizeof(tname), "blk-%s-%d", ident, i);
pthread_set_name_np(bc->bc_btid[i], tname);
}
return (bc);
err:
+ if (bc != NULL) {
+ void *jval;
+ if (bc->bc_cond) {
+ pthread_mutex_lock(&bc->bc_mtx);
+ bc->bc_closing = 1;
+ pthread_mutex_unlock(&bc->bc_mtx);
+ pthread_cond_broadcast(&bc->bc_cond);
+ for (int i = 0; i < BLOCKIF_NUMTHR; i++)
+ if (bc->bc_btid[i])
+ pthread_join(bc->bc_btid[i], &jval);
+ pthread_cond_destroy(&bc->bc_cond);
+ }
+ if (bc->bc_mtx)
+ pthread_mutex_destroy(&bc->bc_mtx);
+ if (bc->bc_work_done_cond)
+ pthread_cond_destroy(&bc->bc_work_done_cond);
+ free(bc);
+ }
if (fd >= 0)
close(fd);
return (NULL);
@@ -806,6 +834,7 @@
int
blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq)
{
+ struct blockif_sig_elem bse;
struct blockif_elem *be;
assert(bc->bc_magic == BLOCKIF_SIG);
@@ -849,11 +878,10 @@
* Interrupt the processing thread to force it return
* prematurely via it's normal callback path.
*/
+ pthread_mutex_init(&bse.bse_mtx, NULL);
+ pthread_cond_init(&bse.bse_cond, NULL);
while (be->be_status == BST_BUSY) {
- struct blockif_sig_elem bse, *old_head;
-
- pthread_mutex_init(&bse.bse_mtx, NULL);
- pthread_cond_init(&bse.bse_cond, NULL);
+ struct blockif_sig_elem *old_head;
bse.bse_pending = 1;
@@ -872,6 +900,8 @@
pthread_mutex_unlock(&bse.bse_mtx);
}
+ pthread_mutex_destroy(&bse.bse_mtx);
+ pthread_cond_destroy(&bse.bse_cond);
pthread_mutex_unlock(&bc->bc_mtx);
/*
@@ -895,7 +925,7 @@
pthread_mutex_lock(&bc->bc_mtx);
bc->bc_closing = 1;
if (bc->bc_resize_event != NULL)
- mevent_disable(bc->bc_resize_event);
+ mevent_delete(bc->bc_resize_event);
pthread_mutex_unlock(&bc->bc_mtx);
pthread_cond_broadcast(&bc->bc_cond);
for (i = 0; i < BLOCKIF_NUMTHR; i++)
@@ -908,6 +938,9 @@
*/
bc->bc_magic = 0;
close(bc->bc_fd);
+ pthread_mutex_destroy(&bc->bc_mtx);
+ pthread_cond_destroy(&bc->bc_cond);
+ pthread_cond_destroy(&bc->bc_work_done_cond);
free(bc);
return (0);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jun 29, 5:28 PM (4 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34440620
Default Alt Text
D57887.diff (3 KB)
Attached To
Mode
D57887: Fix some leaks in usr.sbin/bhyve/block_if.c
Attached
Detach File
Event Timeline
Log In to Comment