mirror of https://github.com/ericonr/sndio.git
fix memory leaks
This commit is contained in:
parent
61c00bcef2
commit
3edbce0c18
|
@ -73,10 +73,11 @@ listen_close(struct listen *f)
|
||||||
|
|
||||||
if (f->path != NULL) {
|
if (f->path != NULL) {
|
||||||
unlink(f->path);
|
unlink(f->path);
|
||||||
free(f->path);
|
xfree(f->path);
|
||||||
}
|
}
|
||||||
file_del(f->file);
|
file_del(f->file);
|
||||||
close(f->fd);
|
close(f->fd);
|
||||||
|
xfree(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -108,7 +109,7 @@ listen_new_un(char *path)
|
||||||
f->file = file_new(&listen_fileops, f, path, 1);
|
f->file = file_new(&listen_fileops, f, path, 1);
|
||||||
if (f->file == NULL)
|
if (f->file == NULL)
|
||||||
goto bad_close;
|
goto bad_close;
|
||||||
f->path = strdup(path);
|
f->path = xstrdup(path);
|
||||||
if (f->path == NULL) {
|
if (f->path == NULL) {
|
||||||
perror("strdup");
|
perror("strdup");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -350,7 +350,7 @@ midi_out(struct midi *oep, unsigned char *idata, int icount)
|
||||||
void
|
void
|
||||||
port_log(struct port *p)
|
port_log(struct port *p)
|
||||||
{
|
{
|
||||||
log_puts(p->path);
|
midi_log(p->midi);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -440,8 +440,15 @@ int
|
||||||
port_open(struct port *c)
|
port_open(struct port *c)
|
||||||
{
|
{
|
||||||
c->mio = miofile_new(c);
|
c->mio = miofile_new(c);
|
||||||
if (c->mio == NULL)
|
if (c->mio == NULL) {
|
||||||
|
if (log_level >= 1) {
|
||||||
|
port_log(c);
|
||||||
|
log_puts(": ");
|
||||||
|
log_puts(c->path);
|
||||||
|
log_puts(": failed to open midi port\n");
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
c->state = PORT_INIT;
|
c->state = PORT_INIT;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
17
sndiod/opt.c
17
sndiod/opt.c
|
@ -119,3 +119,20 @@ opt_byname(char *name, unsigned int num)
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
opt_del(struct opt *o)
|
||||||
|
{
|
||||||
|
struct opt **po;
|
||||||
|
|
||||||
|
for (po = &opt_list; *po != o; po = &(*po)->next) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (*po == NULL) {
|
||||||
|
log_puts("opt_del: not on list\n");
|
||||||
|
panic();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
*po = o->next;
|
||||||
|
xfree(o);
|
||||||
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ extern struct opt *opt_list;
|
||||||
|
|
||||||
struct opt *opt_new(char *, struct dev *, int, int, int, int,
|
struct opt *opt_new(char *, struct dev *, int, int, int, int,
|
||||||
int, int, int, unsigned int);
|
int, int, int, unsigned int);
|
||||||
int opt_bind(struct opt *);
|
void opt_del(struct opt *);
|
||||||
struct opt *opt_byname(char *, unsigned int);
|
struct opt *opt_byname(char *, unsigned int);
|
||||||
|
|
||||||
#endif /* !defined(OPT_H) */
|
#endif /* !defined(OPT_H) */
|
||||||
|
|
|
@ -471,6 +471,8 @@ main(int argc, char **argv)
|
||||||
listen_close(listen_list);
|
listen_close(listen_list);
|
||||||
while (sock_list != NULL)
|
while (sock_list != NULL)
|
||||||
sock_close(sock_list);
|
sock_close(sock_list);
|
||||||
|
while (opt_list != NULL)
|
||||||
|
opt_del(opt_list);
|
||||||
for (d = dev_list; d != NULL; d = d->next)
|
for (d = dev_list; d != NULL; d = d->next)
|
||||||
dev_done(d);
|
dev_done(d);
|
||||||
for (p = port_list; p != NULL; p = p->next)
|
for (p = port_list; p != NULL; p = p->next)
|
||||||
|
@ -485,5 +487,6 @@ main(int argc, char **argv)
|
||||||
filelist_done();
|
filelist_done();
|
||||||
rmdir(base);
|
rmdir(base);
|
||||||
unsetsig();
|
unsetsig();
|
||||||
|
mem_stats();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,3 +253,15 @@ mem_stats(void)
|
||||||
log_puts("\n");
|
log_puts("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
mem_strdup(const char *s, char *tag)
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
void *p;
|
||||||
|
|
||||||
|
size = strlen(s) + 1;
|
||||||
|
p = mem_alloc(size, tag);
|
||||||
|
memcpy(p, s, size);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
|
@ -28,10 +28,12 @@ void log_flush(void);
|
||||||
|
|
||||||
//void *xmalloc(size_t);
|
//void *xmalloc(size_t);
|
||||||
void *mem_alloc(size_t, char *);
|
void *mem_alloc(size_t, char *);
|
||||||
|
char *mem_strdup(const char *, char *);
|
||||||
void mem_free(void *);
|
void mem_free(void *);
|
||||||
void mem_stats(void);
|
void mem_stats(void);
|
||||||
|
|
||||||
#define xmalloc(s) (mem_alloc((s), (char *)__func__))
|
#define xmalloc(s) (mem_alloc((s), (char *)__func__))
|
||||||
|
#define xstrdup(s) (mem_strdup((s), (char *)__func__))
|
||||||
#define xfree(p) (mem_free((p)))
|
#define xfree(p) (mem_free((p)))
|
||||||
|
|
||||||
void memrnd(void *, size_t);
|
void memrnd(void *, size_t);
|
||||||
|
|
Loading…
Reference in New Issue