Skip to content

Commit 413d089

Browse files
authored
Fix PCM destructor 'segfault'
PCM module used to segfaults after 0.4.4 because the added destructor missed a case when the buffer is loaded directly instead from a file or converted.
1 parent a04d5ed commit 413d089

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

CriCodecs/pcm.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ struct PCM{
385385
double *PCM_IEEE_64; /* 64 float bits */
386386
unsigned int ColumnSize;
387387
bool converted;
388+
bool loaded;
388389
riff wav;
389390

390391
PCM(){
@@ -397,10 +398,11 @@ struct PCM{
397398
PCM_IEEE_64 = NULL;
398399
wav = {};
399400
converted = false;
401+
loaded = false;
400402
}
401403

402404
~PCM(){
403-
if(WAVEBuffer != NULL)
405+
if(WAVEBuffer != NULL && !loaded)
404406
delete[] WAVEBuffer;
405407
if(PCM_16 != NULL && converted)
406408
delete[] PCM_16;
@@ -543,6 +545,7 @@ struct PCM{
543545
}
544546

545547
unsigned char* GetWaveBuffer(unsigned int SampleCount, unsigned int Channels, unsigned int SampleRate, bool Looping){
548+
loaded = false;
546549
unsigned int header_size = Looping ? 0x70 : 0x2C;
547550
wav.size = header_size + SampleCount * Channels * sizeof(short);
548551
WAVEBuffer = new unsigned char[wav.size];
@@ -554,6 +557,7 @@ struct PCM{
554557

555558
/* This function should not be used for files over 2GB in size. */
556559
char LoadFromFile(const char* Filename){
560+
loaded = false;
557561
FILE* fp = fopen(Filename, "rb");
558562
fseek(fp, 0, 2);
559563
long long size = ftell(fp);
@@ -568,8 +572,8 @@ struct PCM{
568572
return load();
569573
}
570574

571-
/* the given buffer will be called by delete[] after the object distructs. */
572575
char LoadDirect(unsigned char* Buffer){
576+
loaded = true;
573577
WAVEBuffer = Buffer;
574578
return load();
575579
}

CriCodecs/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
setup(
44
name="CriCodecs",
5-
version="0.2.2",
5+
version="0.2.3",
66
ext_modules=[Extension('CriCodecs', ["adx.cpp", "CriCodecs.cpp", "crilayla.cpp", "hca.cpp"])]
77
)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="PyCriCodecs",
6-
version="0.4.5",
6+
version="0.4.6",
77
description="Python frontend with a C++ backend of managing Criware files of all kinds.",
88
packages=["PyCriCodecs"],
99
ext_modules=[Extension('CriCodecs', ["CriCodecs\\CriCodecs.cpp"], include_dirs=[os.path.realpath("CriCodecs")])]

0 commit comments

Comments
 (0)