diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2017-03-26 16:45:34 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2017-03-26 16:45:34 +0200 |
commit | 019bb580da25ccfb414c9b71ce5c0743cf86d6fd (patch) | |
tree | 1e9a474220540f8ff2d2c62773384e38d1469d92 /sys/src/9/port/devsd.c | |
parent | 1889aa50c3727e7c09da16cacfbfecd72860511b (diff) |
devsd: check return value of ifc->enable(), don't leak unit name/user strings
Diffstat (limited to 'sys/src/9/port/devsd.c')
-rw-r--r-- | sys/src/9/port/devsd.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/sys/src/9/port/devsd.c b/sys/src/9/port/devsd.c index 18684b3d7..dd1feeedf 100644 --- a/sys/src/9/port/devsd.c +++ b/sys/src/9/port/devsd.c @@ -293,30 +293,31 @@ sdgetunit(SDev* sdev, int subno) qunlock(&sdev->unitlock); return nil; } + if((unit = malloc(sizeof(SDunit))) == nil){ qunlock(&sdev->unitlock); return nil; } sdev->unitflg[subno] = 1; - snprint(buf, sizeof buf, "%s%x", sdev->name, subno); kstrdup(&unit->name, buf); kstrdup(&unit->user, eve); unit->perm = 0555; unit->subno = subno; unit->dev = sdev; - + if(sdev->enabled == 0 && sdev->ifc->enable) - sdev->ifc->enable(sdev); - sdev->enabled = 1; + sdev->enabled = sdev->ifc->enable(sdev); /* * No need to lock anything here as this is only * called before the unit is made available in the * sdunit[] array. */ - if(unit->dev->ifc->verify(unit) == 0){ + if(sdev->enabled == 0 || unit->dev->ifc->verify(unit) == 0){ qunlock(&sdev->unitlock); + free(unit->name); + free(unit->user); free(unit); return nil; } |