Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgos_wifi_get_connected_ssid() causes memory leak if called in mJS #25

Open
tripflex opened this issue Apr 12, 2019 · 0 comments
Open

Comments

@tripflex
Copy link
Contributor

tripflex commented Apr 12, 2019

As mentioned in Gitter chat, there's no easy way in mJS to get the connected SSID or connection status, without a memory leak, or extra mJS code to get the pointer, then the value, then free afterwards.

As i'm sure others will need this in mJS -- there should be an easy way to get these values without having the memory leak or using a hack in mJS to get the value then free it.


Provided by @cpq on Gitter
one way of doing it could be something like that - FFI as a void*, not as char *

let func = ffi('void *foo()');
let strlen = ffi('int strlen(char *)');
let ptr = f();
let str = mkstr(ptr, strlen(ptr));
Sys.free(ptr);

so the idea is that by FFI-ing void *, you get the pointer

UPDATE: The above code DOES NOT WORK CORRECTLY -- I had to add my own strlen with a void * arg to make this work:

int smyles_strlen(void *something){
    return strlen( (const char*)something );
}

Then use:

let smyL = ffi('int smyles_strlen(void *)');
let ssidF = ffi("void *mgos_wifi_get_connected_ssid()");
let ssidP = ssidF();
let ssidS = mkstr(ssidP, smyL(ssidP));
... do something with ssidS
Sys.free(ssidP);

IT SHOULDN'T BE THIS DIFFICULT TO GET SSID FROM mJS!!

@tripflex tripflex changed the title Add mJS method for getting connected SSID and connection status mgos_wifi_get_connected_ssid() causes memory leak if called in mJS Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant