[Freeswitch-users] Added close method to spidermonkey_odbc

Chris Danielson chris at maxpowersoft.com
Thu Apr 3 17:52:32 PDT 2008


I found that some of my long running JavaScript scripts were holding 
connections open for way too long.  I debugged and valgrind'd this 
change in order to make sure that we do not have any memory leaks.  I'd 
appreciate a second opinion.

http://jira.freeswitch.org/browse/MODLANG-55

Kind Regards,
Chris Danielson


Index: mod_spidermonkey_odbc.c
===================================================================
--- mod_spidermonkey_odbc.c     (revision 8009)
+++ mod_spidermonkey_odbc.c     (working copy)
@@ -79,15 +79,15 @@
static void destroy_odbc_obj(odbc_obj_t ** objp)
{
       odbc_obj_t *obj = *objp;
-
+    if (obj == NULL) return;
       if (obj->stmt) {
               SQLFreeHandle(SQL_HANDLE_STMT, obj->stmt);
       }
-       if (obj->handle) {
-               switch_odbc_handle_destroy(&obj->handle);
-       }
-       switch_safe_free(obj->colbuf);
-       switch_safe_free(obj->code);
+    if (obj->handle) {
+       switch_odbc_handle_destroy(&obj->handle);
+    }
+    switch_safe_free(obj->colbuf);
+    switch_safe_free(obj->code);
       switch_safe_free(obj);
}

@@ -156,11 +156,12 @@

static void odbc_destroy(JSContext * cx, JSObject * obj)
{
-       odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
-
+       if (obj == NULL) return;
+    odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
       if (odbc_obj) {
               destroy_odbc_obj(&odbc_obj);
-       }
+           JS_SetPrivate(cx, obj, NULL);
+    }
}

static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, 
jsval *argv, jsval *rval)
@@ -405,6 +406,12 @@

}

+static JSBool odbc_close(JSContext * cx, JSObject * obj, uintN argc, 
jsval *argv, jsval *rval)
+{
+     odbc_destroy(cx, obj);
+     return JS_TRUE;
+}
+
enum odbc_tinyid {
       odbc_NAME
};
@@ -417,6 +424,7 @@
       {"numRows", odbc_num_rows, 1},
       {"nextRow", odbc_next_row, 1},
       {"getData", odbc_get_data, 1},
+    {"close", odbc_close, 1},
       {0}
};




More information about the FreeSWITCH-users mailing list