module: fix pointer reference to out-of-scope variable
authorBen Noordhuis <info@bnoordhuis.nl>
Sat, 13 Aug 2011 23:25:39 +0000 (01:25 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Mon, 15 Aug 2011 18:08:18 +0000 (20:08 +0200)
Reported by Tom Hughes.

src/node.cc

index 527d11c..0ae59e8 100644 (file)
@@ -1574,6 +1574,7 @@ typedef void (*extInit)(Handle<Object> exports);
 // DLOpen is node.dlopen(). Used to load 'module.node' dynamically shared
 // objects.
 Handle<Value> DLOpen(const v8::Arguments& args) {
+  node_module_struct compat_mod;
   HandleScope scope;
 
   if (args.Length() < 2) return Undefined();
@@ -1616,10 +1617,13 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
   // Get the init() function from the dynamically shared object.
   node_module_struct *mod = static_cast<node_module_struct *>(dlsym(handle, symstr));
   free(symstr);
+  symstr = NULL;
+
   // Error out if not found.
   if (mod == NULL) {
     /* Start Compatibility hack: Remove once everyone is using NODE_MODULE macro */
-    node_module_struct compat_mod;
+    memset(&compat_mod, 0, sizeof compat_mod);
+
     mod = &compat_mod;
     mod->version = NODE_MODULE_VERSION;