From 59bf6dc059ca5f9e436d131e2a90d789644a670e Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Fri, 13 Jan 2023 18:15:51 +0100 Subject: 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 --- src/Fl_Native_File_Chooser_Kdialog.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Fl_Native_File_Chooser_Kdialog.cxx b/src/Fl_Native_File_Chooser_Kdialog.cxx index bac054184..b2c100879 100644 --- a/src/Fl_Native_File_Chooser_Kdialog.cxx +++ b/src/Fl_Native_File_Chooser_Kdialog.cxx @@ -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); -- cgit v1.2.3