Skip to content

Commit 784b496

Browse files
committed
FLTK: fix memory leaks
1 parent e64314f commit 784b496

File tree

11 files changed

+146
-70
lines changed

11 files changed

+146
-70
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2019-11-30 (0.12.17)
2+
FLTK: fix memory leaks
3+
FLTK: implement audio
4+
15
2019-11-30 (0.12.17)
26
ANDROID: fix module access in newer android versions.
37
UI: code cleanup

src/platform/fltk/BasicEditor.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ BasicEditor::BasicEditor(int x, int y, int w, int h, StatusBar *status) :
161161
}
162162

163163
BasicEditor::~BasicEditor() {
164+
buffer(nullptr);
165+
delete _textbuf;
164166
delete _stylebuf;
165167
}
166168

src/platform/fltk/BasicEditor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct StatusBar {
2222

2323
struct BasicEditor : public Fl_Text_Editor {
2424
BasicEditor(int x, int y, int w, int h, StatusBar *status);
25-
~BasicEditor();
25+
virtual ~BasicEditor();
2626

2727
bool findText(const char *find, bool forward, bool updatePos);
2828
int handle(int e);

src/platform/fltk/MainWindow.cxx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ bool MainWindow::basicMain(EditorWidget *editWidget,
120120
if (!toolExec) {
121121
if (opt_ide == IDE_NONE) {
122122
// run in a separate window with the ide hidden
123-
fullScreen = new BaseWindow(w(), h(), _system);
123+
fullScreen = new BaseWindow(w(), h(), _runtime);
124124
fullScreen->box(FL_NO_BOX);
125125
fullScreen->callback(quit_cb);
126126
fullScreen->add(_out);
@@ -143,7 +143,7 @@ bool MainWindow::basicMain(EditorWidget *editWidget,
143143
restart = false;
144144
runMode = run_state;
145145
chdir(path);
146-
success = _system->run(filename);
146+
success = _runtime->run(filename);
147147
}
148148
while (restart);
149149

@@ -454,7 +454,7 @@ void MainWindow::font_size_incr(Fl_Widget *w, void *eventData) {
454454
if (size < MAX_FONT_SIZE) {
455455
editWidget->setFontSize(size + 1);
456456
updateConfig(editWidget);
457-
_system->setFontSize(size + 1);
457+
_runtime->setFontSize(size + 1);
458458
}
459459
} else {
460460
handle(EVENT_INCREASE_FONT);
@@ -468,7 +468,7 @@ void MainWindow::font_size_decr(Fl_Widget *w, void *eventData) {
468468
if (size > MIN_FONT_SIZE) {
469469
editWidget->setFontSize(size - 1);
470470
updateConfig(editWidget);
471-
_system->setFontSize(size - 1);
471+
_runtime->setFontSize(size - 1);
472472
}
473473
} else {
474474
handle(EVENT_DECREASE_FONT);
@@ -907,20 +907,12 @@ bool initialise(int argc, char **argv) {
907907
return true;
908908
}
909909

910-
/**
911-
* save application state at program exit
912-
*/
913-
void save_profile(void) {
914-
wnd->_profile->save(wnd);
915-
}
916-
917910
/**
918911
* application entry point
919912
*/
920913
int main(int argc, char **argv) {
921914
int result;
922915
if (initialise(argc, argv)) {
923-
atexit(save_profile);
924916
Fl::run();
925917
result = 0;
926918
} else {
@@ -1012,7 +1004,7 @@ MainWindow::MainWindow(int w, int h) :
10121004
_outputGroup->labelfont(FL_HELVETICA);
10131005
_outputGroup->user_data((void *)gw_output);
10141006
_out = new GraphicsWidget(x1, y1 + 1, x2, y2 -1);
1015-
_system = new Runtime(x2, y2 - 1, DEF_FONT_SIZE);
1007+
_runtime = new Runtime(x2, y2 - 1, DEF_FONT_SIZE);
10161008
_outputGroup->resizable(_out);
10171009
_outputGroup->end();
10181010
_tabGroup->resizable(_outputGroup);
@@ -1023,7 +1015,9 @@ MainWindow::MainWindow(int w, int h) :
10231015
}
10241016

10251017
MainWindow::~MainWindow() {
1026-
delete _system;
1018+
_profile->save(this);
1019+
delete _profile;
1020+
delete _runtime;
10271021
}
10281022

10291023
Fl_Group *MainWindow::createTab(GroupWidgetEnum groupWidgetEnum, const char *label) {
@@ -1341,7 +1335,7 @@ void MainWindow::setTitle(Fl_Window *widget, const char *filename) {
13411335
}
13421336

13431337
void MainWindow::setBreak() {
1344-
_system->setExit(false);
1338+
_runtime->setExit(false);
13451339
runMode = break_state;
13461340
}
13471341

@@ -1363,15 +1357,15 @@ bool MainWindow::isIdeHidden() {
13631357

13641358
void MainWindow::resize(int x, int y, int w, int h) {
13651359
BaseWindow::resize(x, y, w, h);
1366-
_system->resize(_out->w(), _out->h());
1360+
_runtime->resize(_out->w(), _out->h());
13671361
}
13681362

13691363
void MainWindow::resizeDisplay(int x, int y, int w, int h) {
13701364
// resize the graphics widget (output tab child)
13711365
_out->resize(x, y, w, h);
13721366

13731367
// resize the runtime platforn
1374-
_system->resize(w, h);
1368+
_runtime->resize(w, h);
13751369
}
13761370

13771371
/**
@@ -1398,7 +1392,7 @@ bool MainWindow::logPrint() {
13981392

13991393
int MainWindow::handle(int e) {
14001394
int result;
1401-
if (getSelectedTab() == _outputGroup && _system->handle(e)) {
1395+
if (getSelectedTab() == _outputGroup && _runtime->handle(e)) {
14021396
result = 1;
14031397
} else {
14041398
result = BaseWindow::handle(e);

src/platform/fltk/MainWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct MainWindow : public BaseWindow {
149149

150150
// display system
151151
GraphicsWidget *_out;
152-
Runtime *_system;
152+
Runtime *_runtime;
153153

154154
// main output
155155
Fl_Group *_outputGroup;

src/platform/fltk/display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
struct Font {
1818
Font(Fl_Font font, Fl_Fontsize size) : _font(font), _size(size) {}
19+
virtual ~Font() {}
1920
void setCurrent() { fl_font(_font, _size); }
2021

2122
private:

src/platform/fltk/runtime.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ Runtime::Runtime(int w, int h, int defsize) : System() {
4545
_output->construct();
4646
_output->setTextColor(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND);
4747
_output->setFontSize(defsize);
48-
open_audio();
48+
audio_open();
4949
}
5050

5151
Runtime::~Runtime() {
52-
close_audio();
52+
delete _output;
53+
audio_close();
5354
}
5455

5556
void Runtime::alert(const char *title, const char *message) {

src/platform/fltk/runtime.h

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

1515
struct Runtime : public System {
1616
Runtime(int w, int h, int defSize);
17-
~Runtime();
17+
virtual ~Runtime();
1818

1919
void addShortcut(const char *) {}
2020
void alert(const char *title, const char *message);

src/platform/fltk/utils.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
//
88

99
#include <config.h>
10+
#if !defined(_Win32)
11+
#include <sys/socket.h>
12+
#endif
1013
#include <stdint.h>
1114
#include "lib/str.h"
1215
#include "utils.h"

0 commit comments

Comments
 (0)