Skip to content

Commit e6d6816

Browse files
mpoulleterikd
authored andcommitted
make_sine.c: small code cleanup.
make_sine.c: fix typo in output message. make_sine.c: use return instead of exit in main. make_sine.c: unify error messages. make_sine.c: return error code if malloc fails. make_sine.c: free memory and close file handle in error case.
1 parent 9923b2a commit e6d6816

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/make_sine.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ main (void)
5555
int *buffer ;
5656

5757
if (! (buffer = malloc (2 * SAMPLE_COUNT * sizeof (int))))
58-
{ printf ("Malloc failed.\n") ;
59-
exit (0) ;
58+
{ printf ("Error : Malloc failed.\n") ;
59+
return 1 ;
6060
} ;
6161

6262
memset (&sfinfo, 0, sizeof (sfinfo)) ;
@@ -83,8 +83,10 @@ main (void)
8383
} ;
8484
}
8585
else
86-
{ printf ("makesine can only generate mono or stereo files.\n") ;
87-
exit (1) ;
86+
{ printf ("Error : make_sine can only generate mono or stereo files.\n") ;
87+
sf_close (file) ;
88+
free (buffer) ;
89+
return 1 ;
8890
} ;
8991

9092
if (sf_write_int (file, buffer, sfinfo.channels * SAMPLE_COUNT) !=

0 commit comments

Comments
 (0)