Fix memory leak in the error handling code path of failed device

creation. From jsg@
This commit is contained in:
Alexandre Ratchov 2012-04-04 13:33:32 +02:00
parent cb82b78c1c
commit 9f12e52145
1 changed files with 5 additions and 5 deletions

View File

@ -115,11 +115,6 @@ dev_new(char *path, unsigned mode,
struct dev *d;
unsigned *pnum, i;
d = malloc(sizeof(struct dev));
if (d == NULL) {
perror("malloc");
exit(1);
}
pnum = (mode & MODE_THRU) ? &dev_thrnum : &dev_sndnum;
if (*pnum == DEV_NMAX) {
#ifdef DEBUG
@ -128,6 +123,11 @@ dev_new(char *path, unsigned mode,
#endif
return NULL;
}
d = malloc(sizeof(struct dev));
if (d == NULL) {
perror("malloc");
exit(1);
}
d->num = (*pnum)++;
if (mode & MODE_THRU)
d->num += DEV_NMAX;