diff options
author | Taylor Holberton <tay10r@protonmail.com> | 2020-04-20 20:23:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-20 20:23:25 -0700 |
commit | 67cca676121ec99bd31caf9e70e888280b9399c8 (patch) | |
tree | 9433f9639378e460c829f86aa737388e4ca633f8 | |
parent | 2feb925cedc25a761d35e32edc37a54a11ebad1d (diff) | |
parent | 859adb2d2f4cd38d264d018404da5b8d09fd854a (diff) |
Merge pull request #151 from mgaio/fix/pcm_open_failure
pcm_hw_close: avoid SIGSEGV when pcm_hw_open fail
-rw-r--r-- | src/pcm.c | 8 | ||||
-rw-r--r-- | src/pcm_hw.c | 1 |
2 files changed, 6 insertions, 3 deletions
@@ -898,7 +898,7 @@ struct pcm *pcm_open(unsigned int card, unsigned int device, if (!pcm->snd_node || pcm_type != SND_NODE_TYPE_PLUGIN) { oops(pcm, -ENODEV, "no device (hw/plugin) for card(%u), device(%u)", card, device); - goto fail_close; + goto fail_close_dev_node; } pcm->ops = &plug_ops; pcm->fd = pcm->ops->open(card, device, flags, &pcm->data, pcm->snd_node); @@ -907,7 +907,7 @@ struct pcm *pcm_open(unsigned int card, unsigned int device, if (pcm->fd < 0) { oops(pcm, errno, "cannot open device (%u) for card (%u)", device, card); - goto fail_close; + goto fail_close_dev_node; } pcm->flags = flags; @@ -950,11 +950,13 @@ fail: if (flags & PCM_MMAP) munmap(pcm->mmap_buffer, pcm_frames_to_bytes(pcm, pcm->buffer_size)); fail_close: + pcm->ops->close(pcm->data); +fail_close_dev_node: #ifdef TINYALSA_USES_PLUGINS if (pcm->snd_node) snd_utils_close_dev_node(pcm->snd_node); #endif - pcm_close(pcm); + free(pcm); return &bad_pcm; } diff --git a/src/pcm_hw.c b/src/pcm_hw.c index 1e67e9b..e25cdae 100644 --- a/src/pcm_hw.c +++ b/src/pcm_hw.c @@ -97,6 +97,7 @@ static int pcm_hw_open(unsigned int card, unsigned int device, fd = open(fn, O_RDWR); if (fd < 0) { + free(hw_data); return fd; } |