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

JS: storage.virtualQuit() does not free the virtual reference #75

Closed
jamisonderek opened this issue Apr 5, 2024 · 5 comments
Closed
Assignees
Labels
bugfix Something isn't working

Comments

@jamisonderek
Copy link
Contributor

Describe the bug.

In my script: I use storage.virtualInit(image) and .virtualMount(). Write some content to "/mnt/bug.txt". Call storage.virtualQuit. When I call usbdisk.start(image) the app hangs; blocked on a resource since virtualQuit did not free the resource.

I think the end of js_storage_virtual_quit needs to do something like:

    if(storage->virtual) {
        storage_file_free(storage->virtual);
        storage->virtual = NULL;
    }
    mjs_return(mjs, MJS_UNDEFINED);

Reproduction

The following script will demonstrate that after a storage.virtualInit that storage.virtualQuit does not release resources, so usbdisk.start will block.

let usbdisk = require("usbdisk");
let storage = require("storage");

let image = __dirpath + "/bug.img";

print("Checking for Image...");
if (storage.exists(image)) {
  print ("Storage Exists. Removing.");
  storage.remove(image);
}

print ("Creating Storage...");
usbdisk.createImage(image, 8 * 1024 * 1024);

print ("Copying Payload...")
storage.virtualInit(image);
storage.virtualMount();
storage.write("/mnt/demo.txt", "Hello");
storage.virtualQuit();

print("Attaching storage...");
usbdisk.start(image);
// BUG: The `usbdisk.start` never returns.

print("Waiting for storage to detatch...");
while (!usbdisk.wasEjected()) {
    delay(1000);
}
print("Stopping storage...");
usbdisk.stop();
print("Done.");

Target

js

Logs

No response

Anything else?

I confirmed that adding the storage_file_free call in js_storage_virtual_quit makes the JavaScript works as expected.

@Willy-JL
Copy link
Member

Willy-JL commented Apr 5, 2024

great catch! will have it fixed asap

@Willy-JL Willy-JL added the bugfix Something isn't working label Apr 5, 2024
@Willy-JL Willy-JL self-assigned this Apr 5, 2024
@Willy-JL Willy-JL added the release-pending This is done, will be in next release label Apr 5, 2024
@Willy-JL
Copy link
Member

Willy-JL commented Apr 5, 2024

fixed via 2f06a01, thank you!

@jamisonderek
Copy link
Contributor Author

It looks like the code got added to js_storage_virtual_mount instead of js_storage_virtual_quit.

@Willy-JL
Copy link
Member

Willy-JL commented Apr 5, 2024

Oh my god hahahahha

I need more sleep, I'm so sorry this was my bad

Willy-JL added a commit that referenced this issue Apr 5, 2024
@Willy-JL Willy-JL changed the title storage.virtualQuit does not free the virtual reference. JS: storage.virtualQuit() does not free the virtual reference Apr 5, 2024
MatthewKuKanich added a commit that referenced this issue Apr 18, 2024
* Notes / comments

* Minor gate ID mapping corrections

* add tlsf as submodule

* libs: tlsf

* Furi: tlsf as allocator

* Furi: heap walker

* shmal fixshesh

* f18: tlsf

* PVS: ignore tlsf

* rework subghz settings, enable tx-rx state on unused gpio pin by default

* SubGHz: Refactor last settings logic

* better subghz settings and more anim unload fixes

by Willy-JL

* cleanup unused debug, set proper log levels

* format

* Ext power amp is always true now

* JS: Add badusb layout support

* js add badusb layout support

by Willy-JL

* fix favorites lockup

* JS: Refactor storage to use array buffers

* JS: Add storage copy() move() mkdir()

* fix apps loading logic

* RFID: Fix success title icon overlap

* Sync apps

* Fix build

* Oops (#75 #79)

* Oops (semaphore vs apilock)

This reverts commit f89f775.

* Desktop: Unload animations before FAP is loaded

* Loader: Add API to start app detached (returns instantly, queues app start)

* Desktop: Fix early animation unload deadlocks

* Update symbols

* Fix build and cleanup

* Fix --no-build

* Desktop: Unload animations before FAP is loaded

* Loader: Add API to start detached (returns instantly, queues event)

* Desktop: Fix early animation unload deadlocks

* JS: Fix default layout handling

* Storage: Default volume label DOLPHIN added to virtual storage

* desktop animations unload apilock revert

+ js layout fix and lfrfid ui fix
by Willy-JL

* update readme and fix hex uppercase

* update changelog

* Storage: Virtual volume label is now set from Image Name

* Storage: Updated virtual storage label to use strlcpy

* Improve error handling, use correct drive id

* Fix FATfs drive IDs (0=/ext 1=/mnt)

* Cleanup import

* Update of NFC emulation pict

Visual edits, perspective enhancement and re-centering on y axis.
-> NFC code edit to follow

* Change y value for graphic asset in nfc_protocol_support.c 

Set y=0 for NFC_dolphin_emulation_51x64 asset so it is coherent with the other uses of this pict.

* MNTM Pack - adding iButton (success) yappy asset

* MNTM Pack - Adding "wait" yappy asset

Note - Only used so far in : iButton / Wardriver / SimonSays

* MNTM Pack - Adding Warning yappy assets (normal & flip vers.)

* IR: Fix crash on duty_cycle=1 (#3568)

* IR: Fix crash on duty_cycle=1
* Infrared: use float around duty_cycle

Co-authored-by: あく <alleteam@gmail.com>

* Furi: Add "out of memory" and "malloc(0)" crash messages (#3574)

Co-authored-by: あく <alleteam@gmail.com>

* Explain RNG differences, add FURI_HAL_RANDOM_MAX (#3565)

* Explain RNG differences, add FURI_HAL_RANDOM_MAX
* Mark FURI_HAL_RANDOM_MAX unsigned

Co-authored-by: あく <alleteam@gmail.com>

* MNTM Pack - Adding Save yappy asset

* Move crypto1 to helpers, add it to the public API (#3567)

* Move crypto1 to helpers, add it to the public API
* F18 API version bump

Co-authored-by: あく <alleteam@gmail.com>

* MNTM Pack - Adding Success yappy asset

* Re-upload of Success asset - oops

Wrong sized vers previously uploaded

* MNTM: Refactor device name to Spoof submenu

* MNTM: Add flipper Shell Color spoofing support

* Misc cleanup/refactor + passes testing

* ASCII of known layouts, pass testing

* I like to moving

* merge upcoming changes

* Parsing function readability refactor

* Ble: set max connection interal same as min, kinda speedups everything

* memmgr: alloc aligned, realloc

* MNTM Pack - Adding Mafia (erf...) yappy asset

* Remove old workflows --nobuild

* Furi: distinct name for auxiliary memory pool

* Furi: put idle and timer thread to mem2

* Furi: fix smal things in allocator

* More cleanup, pass testing

* Archive: Fix .txt file type for /any paths

* MNTM Pack - Adding "done" Yappy (PI) asset

:P

* Update radio stack to v1.19.0 (#3545)

* Update radio stack to v1.19.0
* Ble: set max connection interal same as min, kinda speedups everything

* JS Documentation (#3535)

* Initial JS documentation
* Spelling fix

Co-authored-by: あく <alleteam@gmail.com>

* Fix BLE Spam #85

* Furi: remove aligned_free. Use free instead.

* Desktop/Loader: Unload animations before loading FAPs (#3573)

* Desktop: Unload animations before FAP is loaded
* Loader: Add API to start detached (returns instantly, queues event)
* Desktop: Fix early animation unload deadlocks
* Loader: remove redundant event
* Bump api symbols

Co-authored-by: あく <alleteam@gmail.com>
Co-authored-by: SG <who.just.the.doctor@gmail.com>

* aligned_malloc -> aligned_alloc

* aligned_alloc, parameters order

* Status output !TX/RX on the GDO2 CC1101 pin (#3571)

* Status output !TX/RX on the GDO2 CC1101 pin\
* Fix PVS warnings

Co-authored-by: あく <alleteam@gmail.com>

* Fix build

* update changelog

* MNTM Pack - Adding IR reading yappy asset

* Struct&var refactor for clarity

* Only print end validity when present

Same might be worth doing for type & balance, keeping those as is for now; expiry/EV specifically given the switching logic as it has most potential for misinterpretation of null/0 value

* Typo

* Add Dolphin 3d printing and wardriving animation (#86)

* Add files via upload

* Add files via upload

* Update manifest.txt

* Update manifest.txt

* Rebalance levels

* Naming consistency

* Consistent cycle time

---------

Co-authored-by: Willy-JL <49810075+Willy-JL@users.noreply.github.com>

* fkin windows with case insensitive paths

* [FL-3772] Felica poller (#3570)

* New types for felica poller
* New functions for felica data transmissions
* Felica memory map extended with new fields
* Init/deinit of mbedtls context added for felica encryption
* Functions for session key and mac calculations added
* Raw felica_poller implementation added
* Removed MAC type parameter from check_mac function
* Replaced all data fields needed for auth with context structure
* Clean up felica_poller.c
* Now RC block is filled with random numbers
* New parameter for counting well-read blocks
* Some cleanups
* Felica file save and load logic added
* Now we use card key from context for session key calculation
* Copying card key to card block from auth context when both authentications succeeded, otherwise decrement blocks count by 1
* New felica poller event added
* Moved some data structions to public namespace
* FelicaAuthenticationContext struct moved to felica.h
* Field type and name changed for better ones
* Helper functions for felica_auth added to the app
* New scene for felica card key input added
* Logic for felica key input added
* Auth context request processing added
* Added block index definitions and replaced all index numbers with them
* More macro defines
* Replace nesting with do while block
* New function for write operations mac calculation added
* Replace nesting with do while block
* Make functions static for now because they are used internally
* Wrote some comments
* Raw felica render implementation
* New felica scenes
* Adjusted felica dump rendering according design requirements
* New felica scene added
* Helper for switching scene during unlock added
* Added warning scene and transfer to it
* Moved unlock scene logic to separate files
* Magic number changed
* New felica render logic
* Felica scenes adjusted according to design requirements
* Felica poller cleanups
* Some asserts added and some fixed
* Replcaed asserts to checks in public api
* Fixed pvs warnings in felica_poller
* New event for felica_poller added for incomplete read actions
* Handling of new poller event added
* Update SConscript with felica files
* Update api_symbols.csv with felica functions
* Sync API versions

Co-authored-by: あく <alleteam@gmail.com>

* subghz add manually fixes

* update nfc parser

by zacharyweiss

* update changelog

* aligned_alloc: check that alignment is correct

* unit test: malloc

* unit tests: realloc and test with memory fragmentation

* unit tests: aligned_alloc

* update api

* Allow setting view dispatcher callbacks to NULL

* JS: Fix badusb double free crash with quit()

* Sync apps

- Picopass: Save as LFRFID and improvements (by bettse)
- NFC Magic: Gen4 sync and fixes (by xMasterX)

* Format

* js fix badusb double free crash with quit()

by Willy-JL

* Allow no prefix usage of name_generator_make_detailed_datetime

Remove extra check for NULL since check is present in code already

* BLE Spam: Fix back event deadlocks

* MNTM Pack - Adding RFID Receive/Send yappy graphic assets

Last 2 ones of the static graphic assets ! O_oV

* [FL-3750] Mf Desfire multiple file rights support (#3576)

* mf desfire: remove unused type
* mf desfire: continue reading after failed get free mem cmd
* mf desfire: fix processing read master key settings command
* mf desfire: don't read applications if they are auth protected
* mf desfire: handle multiple rights
* mf desfire: fix PVS warnings
* mf desfire: fix print format
* mf desfire: fix logs
* mf classic: add send frame functions to poller
* unit tests: add test from mfc crypto frame exchange
* mf classic: add documentation
* mf classic: fix incorrect name
* target: fix api version

* Allow empty prefix in name generator

* BLE: Allow bonding with GapPairingNone

* BadKB: Fix mac address for remember on/off

* BadKB: Improve BT Remember handling

* BadKB: Choose BT Pairing security mode (YesNo, PIN Type, Pin Y/N)

* Impl basic favorite ability for WAVs

Namely just for the sake of favorite-ing the cart lock/unlock. Requires changes to WAV player ext fap, as to be PR'd from the Momentum-Apps repo.

* Update WAV fap for compatibility

* Delete assets/dolphin/internal/L1_NoSd_128x49/frame_1.png

* Delete assets/dolphin/internal/L1_NoSd_128x49/frame_2.png

* Delete assets/dolphin/internal/L1_NoSd_128x49/frame_3.png

* Delete assets/dolphin/internal/L1_NoSd_128x49/frame_4.png

* Delete assets/dolphin/internal/L1_NoSd_128x49/frame_5.png

* Replacing frame_0 & meta

* [FL-2969] FuriHal: add ADC API (#3583)

* Examples: remove unused context
* FuriHal: add simple ADC API
* Examples: add ADC example app
* FuriHal: add extended configuration options for ADC API
* FuriHal: add ADC clock configuration, fix calibration routine for single ended mode, new optimized parameters, documentation.
* FuriHal: add FuriHalAdcChannelTEMPSENSOR sampling time note
* FuriHal: update FuriHalAdcChannelVBAT description.
* FuriHal: use insomnia while ADC is acquired.
* Examples: cleanup example_adc a little bit

* Sync WAV Player

* [FL-3679] iButton new UI (#3471)

* iButton new UI
* UI final touches
* Satisfy PVS

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>

* Update tv.ir (#3584)

Co-authored-by: あく <alleteam@gmail.com>

* Allow setting view_dispatcher callbacks to NULL again (#3580)

Co-authored-by: あく <alleteam@gmail.com>

* nfc app: fix false positive verification in bip plugin (#3595)

Co-authored-by: あく <alleteam@gmail.com>

* BLE: Add GapPairingNone support (#3596)

* BLE: Add GapPairingNone support
* FuriHal: cleanup naming in ble gap, remove useless config options

Co-authored-by: あく <alleteam@gmail.com>

* Update symbols

---------

Co-authored-by: Zachary Weiss <zachary.weiss.acct@gmail.com>
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: MX <10697207+xMasterX@users.noreply.github.com>
Co-authored-by: Willy-JL <49810075+Willy-JL@users.noreply.github.com>
Co-authored-by: Nick Shaw <nick.shaw@jetblk.net>
Co-authored-by: Kuronons <110337784+Kuronons@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
Co-authored-by: Astra <93453568+Astrrra@users.noreply.github.com>
Co-authored-by: Nikolay Minaylov <nm29719@gmail.com>
Co-authored-by: Victor Nikitchuk <rainbowkiwifox@gmail.com>
Co-authored-by: Chonk_m <143907552+Davim09@users.noreply.github.com>
Co-authored-by: RebornedBrain <138568282+RebornedBrain@users.noreply.github.com>
Co-authored-by: gornekich <n.gorbadey@gmail.com>
Co-authored-by: KRukus9 <65518085+KRukus9@users.noreply.github.com>
@Willy-JL
Copy link
Member

Fix was released in mntm-002

@Willy-JL Willy-JL removed the release-pending This is done, will be in next release label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Something isn't working
Projects
Archived in project
Development

No branches or pull requests

2 participants