GeezerVison is showing github.com — src: fix memory leak in DLOpen · nodejs/node@b196c1d
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node.cc +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2124,6 +2124,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) { |
2124 | 2124 |
|
2125 | 2125 | if (is_dlopen_error) { |
2126 | 2126 | Local<String> errmsg = OneByteString(env->isolate(), uv_dlerror(&lib)); |
| 2127 | + uv_dlclose(&lib); |
2127 | 2128 | #ifdef _WIN32 |
2128 | 2129 | // Windows needs to add the filename into the error message |
2129 | 2130 | errmsg = String::Concat(errmsg, args[1]->ToString(env->isolate())); |
@@ -2133,10 +2134,12 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) { |
2133 | 2134 | } |
2134 | 2135 |
|
2135 | 2136 | if (mp == nullptr) { |
| 2137 | + uv_dlclose(&lib); |
2136 | 2138 | env->ThrowError("Module did not self-register."); |
2137 | 2139 | return; |
2138 | 2140 | } |
2139 | 2141 | if (mp->nm_version != NODE_MODULE_VERSION) { |
| 2142 | + uv_dlclose(&lib); |
2140 | 2143 | char errmsg[1024]; |
2141 | 2144 | snprintf(errmsg, |
2142 | 2145 | sizeof(errmsg), |
@@ -2146,6 +2149,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) { |
2146 | 2149 | return; |
2147 | 2150 | } |
2148 | 2151 | if (mp->nm_flags & NM_F_BUILTIN) { |
| 2152 | + uv_dlclose(&lib); |
2149 | 2153 | env->ThrowError("Built-in module self-registered."); |
2150 | 2154 | return; |
2151 | 2155 | } |
@@ -2162,6 +2166,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) { |
2162 | 2166 | } else if (mp->nm_register_func != nullptr) { |
2163 | 2167 | mp->nm_register_func(exports, module, mp->nm_priv); |
2164 | 2168 | } else { |
| 2169 | + uv_dlclose(&lib); |
2165 | 2170 | env->ThrowError("Module has no declared entry point."); |
2166 | 2171 | return; |
2167 | 2172 | } |
|