remove malloc'ing of sound_file and sound_wav descriptions

master
Ozkan Sezer 3 years ago
parent 425adebf7b
commit 0e44b4ebf6
  1. 16
      src/sound_file.c
  2. 21
      src/sound_wav.c

@ -17,7 +17,6 @@ static int swap_endian;
static int init(struct options *options)
{
char **parm = options->driver_parm;
char *buf;
swap_endian = 0;
@ -38,18 +37,6 @@ static int init(struct options *options)
fd = stdout;
}
if (strcmp(options->out_file, "-")) {
int len = strlen(sound_file.description) +
strlen(options->out_file) + 8;
if ((buf = (char *)malloc(len)) == NULL)
return -1;
snprintf(buf, len, "%s: %s", sound_file.description,
options->out_file);
sound_file.description = buf;
} else {
sound_file.description = xmp_strdup("stdout");
}
return 0;
}
@ -64,7 +51,6 @@ static void play(void *b, int len)
static void deinit(void)
{
free((void *)sound_file.description);
if (fd && fd != stdout) {
fclose(fd);
}
@ -86,7 +72,7 @@ static void onresume(void)
{
}
static const char *const help[] = {
static const char * const help[] = {
"endian=big", "Force big-endian 16-bit samples",
"endian=little", "Force little-endian 16-bit samples",
NULL

@ -45,8 +45,6 @@ static void write_32l(FILE *f, unsigned int v)
static int init(struct options *options)
{
char *buf;
unsigned int len = 0;
unsigned short chan;
unsigned int sampling_rate, bytes_per_second;
unsigned short bytes_per_frame, bits_per_sample;
@ -65,21 +63,8 @@ static int init(struct options *options)
fd = stdout;
}
if (strcmp(options->out_file, "-")) {
int len = strlen(sound_wav.description) +
strlen(options->out_file) + 8;
if ((buf = (char *)malloc(len)) == NULL)
return -1;
snprintf(buf, len, "%s: %s", sound_wav.description,
options->out_file);
sound_wav.description = buf;
} else {
sound_wav.description = xmp_strdup("WAV writer: stdout");
len = -1;
}
fwrite("RIFF", 1, 4, fd);
write_32l(fd, len);
write_32l(fd, 0); /* will be written when finished */
fwrite("WAVE", 1, 4, fd);
chan = options->format & XMP_FORMAT_MONO ? 1 : 2;
@ -107,7 +92,7 @@ static int init(struct options *options)
write_16l(fd, bits_per_sample);
fwrite("data", 1, 4, fd);
write_32l(fd, len);
write_32l(fd, 0); /* will be written when finished */
size = 0;
@ -136,8 +121,6 @@ static void deinit(void)
fclose(fd);
}
fd = NULL;
free((void *)sound_wav.description);
}
static void flush(void)

Loading…
Cancel
Save