parro-it/libui-node

Crash when OpenFile dialog is closed clicking cancel button

son-link opened this issue · 6 comments

I, firts sorry mi english.
When i use the OpenFile dialog if i close it or press Cancel the program is crass. This us the error messages:

/home/sonlink/proyectos/vid4web/index.js:31
const filename = libui.UiDialogs.openFile(window);
^
Error: basic_string::_M_construct null not valid
at add_btn.onClicked (/home/sonlink/proyectos/vid4web/index.js:31:36)

If i select a file and press Accept works correctly.
I use the last release installed with npm

What OS and version are you using?
What Node.js version?
Are you able to reproduce the problem using one of the example? (node-pad has an open menu that open a file dialog)

OS: Arch Linux
NodeJS: 10.2.1
And, yes, crash in examples/node-pad.js in Open, Save and Save AS

Ok I'll try to reproduce it.

Yes, it's a libui-node bug.


TL;DR: uiOpenFile returns NULL when aborting and we're then freeing the NULL.


Code from libui/test/page5:

static void openFile(uiButton *b, void *data)
{
	char *fn;

	fn = uiOpenFile(parent);
	if (fn == NULL)
		uiLabelSetText(uiLabel(data), "(cancelled)");
	else {
		uiLabelSetText(uiLabel(data), fn);
		uiFreeText(fn);
	}
}

libui-node:

libui-node/src/UiWindow.cc

Lines 166 to 171 in 154e660

static std::string openFile(UiWindow *parent) {
char *char_ptr = uiOpenFile(parent->getHandle());
std::string s(char_ptr);
uiFreeText(char_ptr);
return s;
}

Fixed in version 0.2.1