Skip to content

Commit dc94354

Browse files
committed
Fixed more memory leaks
1 parent ecf4ac8 commit dc94354

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/asar/libstr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ char * readfile(const char * fname, const char * basepath)
3838
data[filesystem->read_file(myfile, data, 0u, datalen)] = 0;
3939
filesystem->close_file(myfile);
4040

41-
if (!is_valid_utf8(data)) asar_throw_error(0, error_type_block, error_id_invalid_utf8);
41+
if (!is_valid_utf8(data))
42+
{
43+
free(data);
44+
asar_throw_error(0, error_type_block, error_id_invalid_utf8);
45+
}
4246
if(check_bom(data)){
4347
data[0] = ' ';
4448
data[1] = ' ';

src/asar/main.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -751,40 +751,41 @@ void assemblefile(const char * filename)
751751
int startif=numif;
752752
if (!filecontents.exists(absolutepath))
753753
{
754-
char * temp= readfile(absolutepath, "");
754+
char * temp = readfile(absolutepath, "");
755755
if (!temp)
756756
{
757757
asar_throw_error(0, error_type_null, vfile_error_to_error_id(asar_get_last_io_error()), filename);
758758

759759
return;
760760
}
761-
file.contents =split(temp, '\n');
762-
file.data = temp;
763-
for (int i=0;file.contents[i];i++)
761+
sourcefile& newfile = filecontents.create(absolutepath);
762+
newfile.contents =split(temp, '\n');
763+
newfile.data = temp;
764+
for (int i=0;newfile.contents[i];i++)
764765
{
765-
file.numlines++;
766-
char * line= file.contents[i];
766+
newfile.numlines++;
767+
char * line= newfile.contents[i];
767768
char * comment = strqchr(line, ';');
768769
if(comment) *comment = 0;
769770
if (!confirmquotes(line)) { callstack_push cs_push(callstack_entry_type::LINE, line, i); asar_throw_error(0, error_type_null, error_id_mismatched_quotes); line[0] = '\0'; }
770-
file.contents[i] = strip_whitespace(line);
771+
newfile.contents[i] = strip_whitespace(line);
771772
}
772-
for(int i=0;file.contents[i];i++)
773+
for(int i=0;newfile.contents[i];i++)
773774
{
774-
char* line = file.contents[i];
775+
char* line = newfile.contents[i];
775776
if(!*line) continue;
776-
for (int j=1;line[strlen(line) - 1] == ',' && file.contents[i+j];j++)
777+
for (int j=1;line[strlen(line) - 1] == ',' && newfile.contents[i+j];j++)
777778
{
778779
// not using strcat because the source and dest overlap here
779-
char* otherline = file.contents[i+j];
780+
char* otherline = newfile.contents[i+j];
780781
char* line_end = line + strlen(line);
781782
while(*otherline) *line_end++ = *otherline++;
782783
*line_end = '\0';
783784
static char nullstr[]="";
784-
file.contents[i+j]=nullstr;
785+
newfile.contents[i+j]=nullstr;
785786
}
786787
}
787-
filecontents.create(absolutepath) = file;
788+
file = newfile;
788789
} else { // filecontents.exists(absolutepath)
789790
file = filecontents.find(absolutepath);
790791
}

0 commit comments

Comments
 (0)