node-oom-heapdump 3.7.5 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
- 23-02-2026 Paul Rütter
1
+ 13-03-2026 Paul Rütter
2
+
3
+ - 3.8.0
4
+ - Fix safety, thread-safety, and resource management bugs in native C++ OOM handler
5
+ See https://github.com/blueconic/node-oom-heapdump/pull/45
6
+
7
+ 13-03-2026 Paul Rütter
8
+
9
+ - 3.7.6
10
+ - Fix for https://github.com/blueconic/node-oom-heapdump/security/dependabot/26 by updating dependencies
11
+
12
+ 23-02-2026 Paul Rütter
2
13
 
3
14
  - 3.7.5
4
15
  - Fix for https://github.com/blueconic/node-oom-heapdump/security/dependabot/21 by updating dependencies
@@ -1,6 +1,7 @@
1
1
  #include <nan.h>
2
2
  #include <v8-profiler.h>
3
3
  #include <stdlib.h>
4
+ #include <atomic>
4
5
  #if defined(_WIN32)
5
6
  #include <time.h>
6
7
  #define snprintf _snprintf
@@ -12,7 +13,7 @@ using namespace v8;
12
13
 
13
14
  char filename[256];
14
15
  bool addTimestamp;
15
- bool processingOOM = false;
16
+ std::atomic<bool> processingOOM(false);
16
17
 
17
18
  class FileOutputStream : public OutputStream
18
19
  {
@@ -43,35 +44,48 @@ size_t RaiseLimit(void *data, size_t current_heap_limit, size_t initial_heap_lim
43
44
 
44
45
  void OnOOMErrorHandler()
45
46
  {
46
- if (processingOOM)
47
+ if (processingOOM.exchange(true))
47
48
  {
48
49
  fprintf(stderr, "FATAL: OnOOMError called more than once.\n");
49
50
  exit(2);
50
51
  }
51
- processingOOM = true;
52
52
 
53
53
  if (addTimestamp)
54
54
  {
55
55
  // Add timestamp to filename
56
56
  time_t rawtime;
57
- struct tm *timeinfo;
57
+ struct tm timeinfo;
58
58
  time(&rawtime);
59
- timeinfo = localtime(&rawtime);
59
+ #if defined(_WIN32)
60
+ localtime_s(&timeinfo, &rawtime);
61
+ #else
62
+ localtime_r(&rawtime, &timeinfo);
63
+ #endif
60
64
 
61
- char *pch;
62
- pch = strstr(filename, ".heapsnapshot");
63
- strncpy(pch, "", 1);
64
- strcat(filename, "-%Y%m%dT%H%M%S.heapsnapshot");
65
+ char *pch = strstr(filename, ".heapsnapshot");
66
+ if (pch != NULL)
67
+ {
68
+ *pch = '\0';
69
+ }
70
+ strncat(filename, "-%Y%m%dT%H%M%S.heapsnapshot", sizeof(filename) - strlen(filename) - 1);
65
71
 
66
72
  char newFilename[256];
67
- strftime(newFilename, sizeof(filename), filename, timeinfo);
68
- strcpy(filename, newFilename);
73
+ if (strftime(newFilename, sizeof(newFilename), filename, &timeinfo) == 0)
74
+ {
75
+ // strftime failed (buffer too small or format error); keep base filename
76
+ snprintf(newFilename, sizeof(newFilename), "%s", filename);
77
+ }
78
+ strncpy(filename, newFilename, sizeof(filename) - 1);
79
+ filename[sizeof(filename) - 1] = '\0';
69
80
  }
70
81
 
71
82
  fprintf(stderr, "Generating Heapdump to '%s' now...\n", filename);
72
83
  FILE *fp = fopen(filename, "w");
73
84
  if (fp == NULL)
85
+ {
86
+ fprintf(stderr, "FATAL: Failed to open '%s' for writing heapdump.\n", filename);
74
87
  abort();
88
+ }
75
89
 
76
90
  auto *isolate = v8::Isolate::GetCurrent();
77
91
 
@@ -90,6 +104,9 @@ void OnOOMErrorHandler()
90
104
  snap->Serialize(&stream, HeapSnapshot::kJSON);
91
105
  fclose(fp);
92
106
 
107
+ // Free the heap snapshot memory
108
+ const_cast<HeapSnapshot *>(snap)->Delete();
109
+
93
110
  fprintf(stderr, "Done! Exiting process now.\n");
94
111
  exit(1);
95
112
  }
@@ -133,6 +150,7 @@ void ParseArgumentsAndSetErrorHandler(const FunctionCallbackInfo<Value> &args)
133
150
  String::Utf8Value fArg(args[0]->ToString());
134
151
  #endif
135
152
  strncpy(filename, (const char *)(*fArg), sizeof(filename) - 1);
153
+ filename[sizeof(filename) - 1] = '\0';
136
154
 
137
155
  #if NODE_VERSION_AT_LEAST(12, 0, 0)
138
156
  addTimestamp = args[1]->BooleanValue(isolate);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-oom-heapdump",
3
- "version": "3.7.5",
3
+ "version": "3.8.0",
4
4
  "description": "Create a V8 heap snapshot when an \"Out of Memory\" error occurs, or create a heap snapshot or CPU profile on request.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -43,14 +43,14 @@
43
43
  "dependencies": {
44
44
  "@mapbox/node-pre-gyp": "2.0.3",
45
45
  "bindings": "^1.5.0",
46
- "chrome-remote-interface": "^0.33.3",
46
+ "chrome-remote-interface": "^0.34.0",
47
47
  "nan": "^2.25.0",
48
48
  "require-main-filename": "^2.0.0",
49
49
  "ws": "^8.19.0"
50
50
  },
51
51
  "overrides": {
52
52
  "@mapbox/node-pre-gyp": {
53
- "tar": "7.5.8"
53
+ "tar": "7.5.11"
54
54
  }
55
55
  }
56
56
  }
package/build/binding.sln DELETED
@@ -1,19 +0,0 @@
1
- Microsoft Visual Studio Solution File, Format Version 12.00
2
- # Visual Studio 2015
3
- Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "node_oom_heapdump_native", "node_oom_heapdump_native.vcxproj", "{B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}"
4
- EndProject
5
- Global
6
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
7
- Debug|x64 = Debug|x64
8
- Release|x64 = Release|x64
9
- EndGlobalSection
10
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
11
- {B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}.Debug|x64.ActiveCfg = Debug|x64
12
- {B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}.Debug|x64.Build.0 = Debug|x64
13
- {B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}.Release|x64.ActiveCfg = Release|x64
14
- {B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}.Release|x64.Build.0 = Release|x64
15
- EndGlobalSection
16
- GlobalSection(SolutionProperties) = preSolution
17
- HideSolutionNode = FALSE
18
- EndGlobalSection
19
- EndGlobal
@@ -1,145 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
- <ItemGroup Label="ProjectConfigurations">
4
- <ProjectConfiguration Include="Debug|x64">
5
- <Configuration>Debug</Configuration>
6
- <Platform>x64</Platform>
7
- </ProjectConfiguration>
8
- <ProjectConfiguration Include="Release|x64">
9
- <Configuration>Release</Configuration>
10
- <Platform>x64</Platform>
11
- </ProjectConfiguration>
12
- </ItemGroup>
13
- <PropertyGroup Label="Globals">
14
- <ProjectGuid>{B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}</ProjectGuid>
15
- <Keyword>Win32Proj</Keyword>
16
- <RootNamespace>node_oom_heapdump_native</RootNamespace>
17
- <IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
18
- <PreferredToolArchitecture>x64</PreferredToolArchitecture>
19
- <WindowsTargetPlatformVersion>10.0.22621.0</WindowsTargetPlatformVersion>
20
- </PropertyGroup>
21
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props"/>
22
- <PropertyGroup Label="Configuration">
23
- <ConfigurationType>DynamicLibrary</ConfigurationType>
24
- </PropertyGroup>
25
- <PropertyGroup Label="Locals">
26
- <PlatformToolset>v143</PlatformToolset>
27
- </PropertyGroup>
28
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props"/>
29
- <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props"/>
30
- <ImportGroup Label="ExtensionSettings"/>
31
- <ImportGroup Label="PropertySheets">
32
- <Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"/>
33
- </ImportGroup>
34
- <PropertyGroup Label="UserMacros"/>
35
- <PropertyGroup>
36
- <ExecutablePath>$(ExecutablePath);$(MSBuildProjectDirectory)\..\bin\;$(MSBuildProjectDirectory)\..\bin\</ExecutablePath>
37
- <IgnoreImportLibrary>true</IgnoreImportLibrary>
38
- <IntDir>$(Configuration)\obj\$(ProjectName)\</IntDir>
39
- <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
40
- <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
41
- <OutDir>$(SolutionDir)$(Configuration)\</OutDir>
42
- <TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.node</TargetExt>
43
- <TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.node</TargetExt>
44
- <TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.node</TargetExt>
45
- <TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.node</TargetExt>
46
- <TargetName>$(ProjectName)</TargetName>
47
- <TargetPath>$(OutDir)\$(ProjectName).node</TargetPath>
48
- </PropertyGroup>
49
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
50
- <ClCompile>
51
- <AdditionalIncludeDirectories>C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\include\node;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\src;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\openssl\config;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\openssl\openssl\include;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\uv\include;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\zlib;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
52
- <AdditionalOptions>/Zc:__cplusplus -std:c++20 /Zm2000 %(AdditionalOptions)</AdditionalOptions>
53
- <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
54
- <BufferSecurityCheck>true</BufferSecurityCheck>
55
- <DebugInformationFormat>OldStyle</DebugInformationFormat>
56
- <DisableSpecificWarnings>4351;4355;4800;4251;4275;4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
57
- <ExceptionHandling>false</ExceptionHandling>
58
- <MinimalRebuild>false</MinimalRebuild>
59
- <MultiProcessorCompilation>true</MultiProcessorCompilation>
60
- <OmitFramePointers>false</OmitFramePointers>
61
- <Optimization>Disabled</Optimization>
62
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
63
- <PreprocessorDefinitions>NODE_GYP_MODULE_NAME=node_oom_heapdump_native;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;_GLIBCXX_USE_CXX11_ABI=1;_FILE_OFFSET_BITS=64;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;NOMINMAX;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;BUILDING_NODE_EXTENSION;DEBUG;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
64
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
65
- <StringPooling>true</StringPooling>
66
- <SuppressStartupBanner>true</SuppressStartupBanner>
67
- <TreatWarningAsError>false</TreatWarningAsError>
68
- <WarningLevel>Level3</WarningLevel>
69
- <WholeProgramOptimization>true</WholeProgramOptimization>
70
- </ClCompile>
71
- <Lib>
72
- <AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
73
- </Lib>
74
- <Link>
75
- <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;delayimp.lib;&quot;C:\\Users\\Paul\\AppData\\Local\\node-gyp\\Cache\\24.13.0\\x64\\node.lib&quot;</AdditionalDependencies>
76
- <AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
77
- <EnableCOMDATFolding>true</EnableCOMDATFolding>
78
- <GenerateDebugInformation>true</GenerateDebugInformation>
79
- <OptimizeReferences>true</OptimizeReferences>
80
- <OutputFile>$(OutDir)$(ProjectName).node</OutputFile>
81
- <SuppressStartupBanner>true</SuppressStartupBanner>
82
- <TargetExt>.node</TargetExt>
83
- <TargetMachine>MachineX64</TargetMachine>
84
- </Link>
85
- <ResourceCompile>
86
- <AdditionalIncludeDirectories>C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\include\node;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\src;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\openssl\config;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\openssl\openssl\include;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\uv\include;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\zlib;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
87
- <PreprocessorDefinitions>NODE_GYP_MODULE_NAME=node_oom_heapdump_native;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;_GLIBCXX_USE_CXX11_ABI=1;_FILE_OFFSET_BITS=64;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;NOMINMAX;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;BUILDING_NODE_EXTENSION;DEBUG;_DEBUG;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
88
- </ResourceCompile>
89
- </ItemDefinitionGroup>
90
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
91
- <ClCompile>
92
- <AdditionalIncludeDirectories>C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\include\node;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\src;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\openssl\config;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\openssl\openssl\include;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\uv\include;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\zlib;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
93
- <AdditionalOptions>/Zc:__cplusplus -std:c++20 /Zm2000 %(AdditionalOptions)</AdditionalOptions>
94
- <BufferSecurityCheck>true</BufferSecurityCheck>
95
- <DebugInformationFormat>OldStyle</DebugInformationFormat>
96
- <DisableSpecificWarnings>4351;4355;4800;4251;4275;4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
97
- <ExceptionHandling>false</ExceptionHandling>
98
- <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
99
- <FunctionLevelLinking>true</FunctionLevelLinking>
100
- <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
101
- <IntrinsicFunctions>true</IntrinsicFunctions>
102
- <MultiProcessorCompilation>true</MultiProcessorCompilation>
103
- <OmitFramePointers>true</OmitFramePointers>
104
- <Optimization>Full</Optimization>
105
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
106
- <PreprocessorDefinitions>NODE_GYP_MODULE_NAME=node_oom_heapdump_native;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;_GLIBCXX_USE_CXX11_ABI=1;_FILE_OFFSET_BITS=64;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;NOMINMAX;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;BUILDING_NODE_EXTENSION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
108
- <RuntimeTypeInfo>false</RuntimeTypeInfo>
109
- <StringPooling>true</StringPooling>
110
- <SuppressStartupBanner>true</SuppressStartupBanner>
111
- <TreatWarningAsError>false</TreatWarningAsError>
112
- <WarningLevel>Level3</WarningLevel>
113
- <WholeProgramOptimization>true</WholeProgramOptimization>
114
- </ClCompile>
115
- <Lib>
116
- <AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
117
- </Lib>
118
- <Link>
119
- <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;delayimp.lib;&quot;C:\\Users\\Paul\\AppData\\Local\\node-gyp\\Cache\\24.13.0\\x64\\node.lib&quot;</AdditionalDependencies>
120
- <AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
121
- <EnableCOMDATFolding>true</EnableCOMDATFolding>
122
- <GenerateDebugInformation>true</GenerateDebugInformation>
123
- <OptimizeReferences>true</OptimizeReferences>
124
- <OutputFile>$(OutDir)$(ProjectName).node</OutputFile>
125
- <SuppressStartupBanner>true</SuppressStartupBanner>
126
- <TargetExt>.node</TargetExt>
127
- <TargetMachine>MachineX64</TargetMachine>
128
- </Link>
129
- <ResourceCompile>
130
- <AdditionalIncludeDirectories>C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\include\node;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\src;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\openssl\config;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\openssl\openssl\include;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\uv\include;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\zlib;C:\Users\Paul\AppData\Local\node-gyp\Cache\24.13.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
131
- <PreprocessorDefinitions>NODE_GYP_MODULE_NAME=node_oom_heapdump_native;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;_GLIBCXX_USE_CXX11_ABI=1;_FILE_OFFSET_BITS=64;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;NOMINMAX;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;BUILDING_NODE_EXTENSION;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
132
- </ResourceCompile>
133
- </ItemDefinitionGroup>
134
- <ItemGroup>
135
- <None Include="..\binding.gyp"/>
136
- </ItemGroup>
137
- <ItemGroup>
138
- <ClCompile Include="..\lib\node_oom_heapdump_native.cc">
139
- <ObjectFileName>$(IntDir)\lib\node_oom_heapdump_native.obj</ObjectFileName>
140
- </ClCompile>
141
- </ItemGroup>
142
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/>
143
- <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets"/>
144
- <ImportGroup Label="ExtensionTargets"/>
145
- </Project>
@@ -1,14 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
- <ItemGroup>
4
- <Filter Include="lib">
5
- <UniqueIdentifier>{2739B19F-16DF-601C-060A-FF86F6A40045}</UniqueIdentifier>
6
- </Filter>
7
- </ItemGroup>
8
- <ItemGroup>
9
- <ClCompile Include="..\lib\node_oom_heapdump_native.cc">
10
- <Filter>lib</Filter>
11
- </ClCompile>
12
- <None Include="..\binding.gyp"/>
13
- </ItemGroup>
14
- </Project>