aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor Holberton <taylorcholberton@gmail.com>2019-06-26 18:01:59 -0400
committerTaylor Holberton <taylorcholberton@gmail.com>2019-06-26 18:01:59 -0400
commit9ec09d5124bc1d1c081d8c910ace663e1f398649 (patch)
tree4c8f98c9ddad703a9eb85aa1475299edc60a131a
parent046f98c7caa5457edd520ad7ebbe8b4f394d2837 (diff)
pcm-readi: Fixed segfault in failure recovery
-rw-r--r--examples/pcm-readi.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/examples/pcm-readi.c b/examples/pcm-readi.c
index 5b85ca6..8722b41 100644
--- a/examples/pcm-readi.c
+++ b/examples/pcm-readi.c
@@ -23,11 +23,11 @@ static size_t read_frames(void **frames)
struct pcm *pcm = pcm_open(card, device, flags, &config);
if (pcm == NULL) {
fprintf(stderr, "failed to allocate memory for PCM\n");
- return EXIT_FAILURE;
+ return 0;
} else if (!pcm_is_ready(pcm)){
pcm_close(pcm);
fprintf(stderr, "failed to open PCM\n");
- return EXIT_FAILURE;
+ return 0;
}
unsigned int frame_size = pcm_frames_to_bytes(pcm, 1);
@@ -37,7 +37,7 @@ static size_t read_frames(void **frames)
if (*frames == NULL) {
fprintf(stderr, "failed to allocate frames\n");
pcm_close(pcm);
- return EXIT_FAILURE;
+ return 0;
}
int read_count = pcm_readi(pcm, *frames, frames_per_sec);
@@ -63,8 +63,8 @@ static int write_file(const void *frames, size_t size)
int main(void)
{
- void *frames;
- size_t size;
+ void *frames = NULL;
+ size_t size = 0;
size = read_frames(&frames);
if (size == 0) {