Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
on-exit-leak-free
Advanced tools
Execute a function on exit without leaking memory, allowing all objects to be garbage collected
This module helps dispose of an object gracefully when the Node.js process exits.
It executes a function with a given parameter
on 'exit'
without leaking memory,
cleaning things up appropriately if the object is garbage collected.
Requires WeakRef
and FinalizationRegistry
, i.e. use Node v14+.
npm i on-exit-leak-free
'use strict'
const { register, unregister } = require('on-exit-leak-free')
const assert = require('assert')
function setup () {
// This object can be safely garbage collected,
// and the resulting shutdown function will not be called.
// There are no leaks.
const obj = { foo: 'bar' }
register(obj, shutdown)
// use registerBeforeExit(obj, shutdown) to execute the function only
// on beforeExit
// call unregister(obj) to remove
}
let shutdownCalled = false
// Please make sure that the function passed to register()
// does not create a closure around unnecessary objects.
function shutdown (obj, eventName) {
console.log(eventName) // beforeExit
shutdownCalled = true
assert.strictEqual(obj.foo, 'bar')
}
setup()
process.on('exit', function () {
assert.strictEqual(shutdownCalled, true)
})
MIT
FAQs
Execute a function on exit without leaking memory, allowing all objects to be garbage collected
The npm package on-exit-leak-free receives a total of 5,428,797 weekly downloads. As such, on-exit-leak-free popularity was classified as popular.
We found that on-exit-leak-free demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.