Skip to content

Commit c15b4cd

Browse files
authored
common : fix file-handle leak in read_wav() (ggml-org#2026)
Now it cleans up in case of error.
1 parent d3cfb6c commit c15b4cd

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

examples/common.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,21 +676,25 @@ bool read_wav(const std::string & fname, std::vector<float>& pcmf32, std::vector
676676

677677
if (wav.channels != 1 && wav.channels != 2) {
678678
fprintf(stderr, "%s: WAV file '%s' must be mono or stereo\n", __func__, fname.c_str());
679+
drwav_uninit(&wav);
679680
return false;
680681
}
681682

682683
if (stereo && wav.channels != 2) {
683684
fprintf(stderr, "%s: WAV file '%s' must be stereo for diarization\n", __func__, fname.c_str());
685+
drwav_uninit(&wav);
684686
return false;
685687
}
686688

687689
if (wav.sampleRate != COMMON_SAMPLE_RATE) {
688690
fprintf(stderr, "%s: WAV file '%s' must be %i kHz\n", __func__, fname.c_str(), COMMON_SAMPLE_RATE/1000);
691+
drwav_uninit(&wav);
689692
return false;
690693
}
691694

692695
if (wav.bitsPerSample != 16) {
693696
fprintf(stderr, "%s: WAV file '%s' must be 16-bit\n", __func__, fname.c_str());
697+
drwav_uninit(&wav);
694698
return false;
695699
}
696700

0 commit comments

Comments
 (0)