Skip to content

Commit 1c784e3

Browse files
mynktlvishnuitta
authored andcommitted
fix(crash): istgt_create_uctl crash due to pthread_detach failure (#193)
Signed-off-by: mayank <[email protected]>
1 parent 969e895 commit 1c784e3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/istgt_lu_ctl.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ typedef struct istgt_uctl_t {
7878
ISTGT_Ptr istgt;
7979
PORTAL portal;
8080
int sock;
81-
pthread_t thread;
8281

8382
int family;
8483
char caddr[MAX_ADDRBUF];
@@ -3779,7 +3778,7 @@ uctlworker(void *arg)
37793778
rc = istgt_uctl_writeline(uctl);
37803779
if (rc != UCTL_CMD_OK) {
37813780
ISTGT_ERRLOG("uctl_writeline() failed\n");
3782-
return (NULL);
3781+
goto error;
37833782
}
37843783

37853784
while (1) {
@@ -3815,6 +3814,7 @@ uctlworker(void *arg)
38153814

38163815
ISTGT_TRACELOG(ISTGT_TRACE_DEBUG, "exiting ctlworker\n");
38173816

3817+
error:
38183818
close(uctl->sock);
38193819
uctl->sock = -1;
38203820
istgt_free_uctl(uctl);
@@ -3845,6 +3845,7 @@ istgt_create_uctl(ISTGT_Ptr istgt, PORTAL_Ptr portal, int sock,
38453845
UCTL_Ptr uctl;
38463846
int rc;
38473847
int i;
3848+
pthread_t thread;
38483849

38493850
uctl = xmalloc(sizeof (*uctl));
38503851
memset(uctl, 0, sizeof (*uctl));
@@ -3966,25 +3967,26 @@ istgt_create_uctl(ISTGT_Ptr istgt, PORTAL_Ptr portal, int sock,
39663967

39673968
/* create new thread */
39683969
#ifdef ISTGT_STACKSIZE
3969-
rc = pthread_create(&uctl->thread, &istgt->attr, &uctlworker,
3970+
rc = pthread_create(&thread, &istgt->attr, &uctlworker,
39703971
(void *)uctl);
39713972
#else
3972-
rc = pthread_create(&uctl->thread, NULL, &uctlworker, (void *)uctl);
3973+
rc = pthread_create(&thread, NULL, &uctlworker, (void *)uctl);
39733974
#endif
39743975
if (rc != 0) {
39753976
ISTGT_ERRLOG("pthread_create() failed\n");
3976-
error_return:
3977+
error_return:
3978+
xfree(uctl->mediadirectory);
39773979
xfree(uctl->portal.label);
39783980
xfree(uctl->portal.host);
39793981
xfree(uctl->portal.port);
39803982
xfree(uctl);
39813983
return (-1);
39823984
}
3983-
rc = pthread_detach(uctl->thread);
3985+
rc = pthread_detach(thread);
39843986
if (rc != 0) {
39853987
ISTGT_ERRLOG("pthread_detach() failed\n");
3986-
goto error_return;
39873988
}
3989+
39883990
return (0);
39893991
}
39903992

0 commit comments

Comments
 (0)