From eaac88163a4844b9efadce39cd33ac3310c7a043 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 14 Aug 2011 01:25:39 +0200 Subject: [PATCH] module: fix pointer reference to out-of-scope variable Reported by Tom Hughes. --- src/node.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index be501619ee2..ec5f4353b85 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1690,6 +1690,7 @@ typedef void (*extInit)(Handle exports); // DLOpen is node.dlopen(). Used to load 'module.node' dynamically shared // objects. Handle DLOpen(const v8::Arguments& args) { + node_module_struct compat_mod; HandleScope scope; if (args.Length() < 2) return Undefined(); @@ -1732,10 +1733,13 @@ Handle DLOpen(const v8::Arguments& args) { // Get the init() function from the dynamically shared object. node_module_struct *mod = static_cast(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;