Fix "alloc-dealloc-mismatch" in Fl_Native_File_Chooser_Kdialog

Error was reported by Address Sanitizer (ASAN) when picking a file.
Platform: Unix/Linux.

==1734703==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete []) on 0x607000108420
    #0 0x7f3357d846ef in operator delete[](void*) ../../../../src/libsanitizer/asan/asan_new_delete.cc:168
    #1 0x4e195f in Fl_Native_File_Chooser_Driver::strfree(char*) ../../src/Fl_Native_File_Chooser.cxx:262
...
0x607000108420 is located 0 bytes inside of 66-byte region [0x607000108420,0x607000108462)
allocated by thread T0 here:
    #0 0x7f3357d0a3ed in __interceptor_strdup ../../../../src/libsanitizer/asan/asan_interceptors.cc:445
    #1 0x57951a in Fl_Kdialog_Native_File_Chooser_Driver::filter(char const*) ../../src/Fl_Native_File_Chooser_Kdialog.cxx:245
    #2 0x4e14a0 in Fl_Native_File_Chooser::filter(char const*) ../../src/Fl_Native_File_Chooser.cxx:176
This commit is contained in:
Albrecht Schlosser 2023-01-13 18:15:51 +01:00
parent a4b33f8e76
commit 59bf6dc059

View File

@ -1,7 +1,7 @@
//
// FLTK native file chooser widget : KDE version
//
// Copyright 2021-2022 by Bill Spitzak and others.
// Copyright 2021-2023 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@ -242,7 +242,8 @@ void Fl_Kdialog_Native_File_Chooser_Driver::filter(const char *f) {
_parsedfilt = strfree(_parsedfilt); // clear previous parsed filter (if any)
_nfilters = 0;
if (!f) return;
_filter = strdup(f);
_filter = new char[strlen(f) + 1];
strcpy(_filter, f);
char *f2 = strdup(f);
char *ptr;
char *part = strtok_r(f2, "\n", &ptr);