Skip to content

Commit b463769

Browse files
committed
Cleanup function BKDataLoadRaw
1 parent 063a3ee commit b463769

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/BKData.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* IN THE SOFTWARE.
2222
*/
2323

24+
#include "BKBase.h"
2425
#include "BKData_internal.h"
2526
#include "BKTone.h"
2627
#include "BKWaveFileReader.h"
@@ -592,6 +593,7 @@ BKInt BKDataSetData(BKData* data, void const* frameData, BKUInt dataSize, BKUInt
592593

593594
BKInt BKDataLoadRaw(BKData* data, FILE* file, BKUInt numChannels, BKEnum params) {
594595
BKSize offset = ftell(file);
596+
BKInt ret = BK_SUCCESS;
595597

596598
if (offset < 0) {
597599
return BK_FILE_ERROR;
@@ -607,19 +609,25 @@ BKInt BKDataLoadRaw(BKData* data, FILE* file, BKUInt numChannels, BKEnum params)
607609
size -= offset;
608610
void* frames = malloc(size);
609611

610-
if (frames == NULL) {
611-
return BK_ALLOCATION_ERROR;
612+
if (!frames) {
613+
ret = BK_ALLOCATION_ERROR;
614+
goto error;
612615
}
613616

614617
fseek(file, offset, SEEK_SET);
615618

616619
if (fread(frames, sizeof(char), size, file) < size) {
617-
return BK_FILE_ERROR;
620+
ret = BK_FILE_ERROR;
621+
goto error;
618622
}
619623

620-
BKInt ret = BKDataSetData(data, frames, (BKUInt)size, numChannels, params);
624+
ret = BKDataSetData(data, frames, (BKUInt)size, numChannels, params);
621625

622-
free(frames);
626+
error: {
627+
if (frames) {
628+
free(frames);
629+
}
630+
}
623631

624632
return ret;
625633
}

0 commit comments

Comments
 (0)