[xdebug-dev] xdebug xdebug/xdebug.c xdebug/xdebug_handler_dbgp.c xdebug/xdebug_var.c xdebug/xdebug_xml.c xdebug/xdebug_xml.h - Fixed bug #453: Memory leaks.

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Mon, 7 Sep 2009 00:03:27 +0200

Date: Mon Sep 7 00:03:27 CEST 2009
User: Derick Rethans
Directory: xdebug

Log Message:
[4.00]
- Fixed bug #453: Memory leaks.
#- Also fixed other memory leaks not mentioned in the report.

Modified files:
           xdebug/xdebug.c (version: 1.456)
           xdebug/xdebug_handler_dbgp.c (version: 1.140)
           xdebug/xdebug_var.c (version: 1.101)
           xdebug/xdebug_xml.c (version: 1.15)
           xdebug/xdebug_xml.h (version: 1.8)

[FILE: /xdebug/xdebug.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.455
retrieving revision 1.456
diff -u -r1.455 -r1.456
--- xdebug/xdebug.c:1.455 Fri Aug 21 15:42:38 2009 GMT
+++ xdebug/xdebug.c Sun Sep 06 20:03:26 2009 GMT
@@ -740,7 +740,7 @@
         return SUCCESS;
 }
 
-static void xdebug_collected_error_dtor(void *dummy, void *elem)
+static void xdebug_llist_string_dtor(void *dummy, void *elem)
 {
         char *s = elem;
 
@@ -836,7 +836,7 @@
         XG(last_exception_trace) = NULL;
         XG(last_eval_statement) = NULL;
         XG(do_collect_errors) = 0;
- XG(collected_errors) = xdebug_llist_alloc(xdebug_collected_error_dtor);
+ XG(collected_errors) = xdebug_llist_alloc(xdebug_llist_string_dtor);
         
         if (idekey && *idekey) {
                 if (XG(ide_key)) {
@@ -920,7 +920,7 @@
         /* Override header generation in SAPI */
         XG(orig_header_handler) = sapi_module.header_handler;
         sapi_module.header_handler = xdebug_header_handler;
- XG(headers) = xdebug_llist_alloc(NULL);
+ XG(headers) = xdebug_llist_alloc(xdebug_llist_string_dtor);
         if (strcmp(sapi_module.name, "cli") == 0) {
                 SG(request_info).no_headers = 1;
         }
@@ -3016,7 +3016,7 @@
 
         if (clear) {
                 xdebug_llist_destroy(XG(collected_errors), NULL);
- XG(collected_errors) = xdebug_llist_alloc(xdebug_collected_error_dtor);
+ XG(collected_errors) = xdebug_llist_alloc(xdebug_llist_string_dtor);
         }
 }
 

[FILE: /xdebug/xdebug_handler_dbgp.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -r1.139 -r1.140
--- xdebug/xdebug_handler_dbgp.c:1.139 Fri Aug 21 15:42:39 2009 GMT
+++ xdebug/xdebug_handler_dbgp.c Sun Sep 06 20:03:27 2009 GMT
@@ -394,7 +394,7 @@
                         element = prepare_search_key(name, &name_length, "", 0);
                         if (ht && zend_hash_index_find(ht, strtoul(element, NULL, 10), (void **) &retval_pp) == SUCCESS) {
                                 retval_p = *retval_pp;
- goto cleanup_num;
+ goto cleanup;
                         }
                         break;
                 case XF_ST_OBJ_PROPERTY:
@@ -426,7 +426,6 @@
         }
 cleanup:
         free(element);
-cleanup_num:
         return retval_p;
 }
 
@@ -1369,11 +1368,11 @@
         XG(status) = DBGP_STATUS_DETACHED;
         xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_strings[DBGP_STATUS_STOPPED]);
         xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_strings[XG(reason)]);
+ XG(context).handler->remote_deinit(&(XG(context)));
         XG(remote_enabled) = 0;
         XG(stdout_redirected) = 0;
         XG(stderr_redirected) = 0;
         XG(stdin_redirected) = 0;
- xdebug_close_socket(context->socket);
 }
 
 
@@ -1858,7 +1857,7 @@
                         full_name = xdstrdup(name);
                 }
                 xdebug_xml_add_attribute_ex(contents, "name", xdstrdup(name), 0, 1);
- xdebug_xml_add_attribute_ex(contents, "fullname", xdstrdup(full_name), 0, 1);
+ xdebug_xml_add_attribute_ex(contents, "fullname", full_name, 0, 1);
 
                 xdebug_xml_add_attribute(contents, "type", "uninitialized");
                 xdebug_xml_add_child(node, contents);
@@ -2061,7 +2060,7 @@
 {
         int i;
 
- for (i = 0; i < 26; i++) {
+ for (i = 0; i < 27; i++) {
                 if (arg->value[i]) {
                         xdfree(arg->value[i]);
                 }
@@ -2245,6 +2244,9 @@
                                 XG(reason) = DBGP_REASON_OK;
                         }
                         XG(lastcmd) = command->name;
+ if (XG(lasttransid)) {
+ xdfree(XG(lasttransid));
+ }
                         XG(lasttransid) = xdstrdup(CMD_OPTION('i'));
                         if (XG(status) != DBGP_STATUS_STOPPING || (XG(status) == DBGP_STATUS_STOPPING && command->flags & XDEBUG_DBGP_POST_MORTEM)) {
                                 command->handler((xdebug_xml_node**) &retval, context, args TSRMLS_CC);
@@ -2278,7 +2280,7 @@
 
 char *xdebug_dbgp_get_revision(void)
 {
- return "$Revision: 1.139 $";
+ return "$Revision: 1.140 $";
 }
 
 static int xdebug_dbgp_cmdloop(xdebug_con *context, int bail TSRMLS_DC)
@@ -2530,8 +2532,12 @@
         response = xdebug_xml_node_init("response");
         xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1");
         xdebug_xml_add_attribute(response, "xmlns:xdebug", "http://xdebug.org/dbgp/xdebug");
- xdebug_xml_add_attribute_ex(response, "command", XG(lastcmd), 0, 0);
- xdebug_xml_add_attribute_ex(response, "transaction_id", XG(lasttransid), 0, 0);
+ /* lastcmd and lasttransid are not always set (for example when the
+ * connection is severed before the first command is send) */
+ if (XG(lastcmd) && XG(lasttransid)) {
+ xdebug_xml_add_attribute_ex(response, "command", XG(lastcmd), 0, 0);
+ xdebug_xml_add_attribute_ex(response, "transaction_id", XG(lasttransid), 0, 0);
+ }
         xdebug_xml_add_attribute(response, "status", xdebug_dbgp_status_strings[XG(status)]);
         xdebug_xml_add_attribute(response, "reason", xdebug_dbgp_reason_strings[XG(reason)]);
 
@@ -2563,8 +2569,12 @@
         response = xdebug_xml_node_init("response");
         xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1");
         xdebug_xml_add_attribute(response, "xmlns:xdebug", "http://xdebug.org/dbgp/xdebug");
- xdebug_xml_add_attribute_ex(response, "command", XG(lastcmd), 0, 0);
- xdebug_xml_add_attribute_ex(response, "transaction_id", XG(lasttransid), 0, 1);
+ /* lastcmd and lasttransid are not always set (for example when the
+ * connection is severed before the first command is send) */
+ if (XG(lastcmd) && XG(lasttransid)) {
+ xdebug_xml_add_attribute_ex(response, "command", XG(lastcmd), 0, 0);
+ xdebug_xml_add_attribute_ex(response, "transaction_id", XG(lasttransid), 0, 0);
+ }
         xdebug_xml_add_attribute(response, "status", xdebug_dbgp_status_strings[XG(status)]);
         xdebug_xml_add_attribute(response, "reason", xdebug_dbgp_reason_strings[XG(reason)]);
 
@@ -2593,7 +2603,10 @@
         xdebug_xml_node_dtor(response);
 
         XG(lastcmd) = NULL;
- XG(lasttransid) = NULL;
+ if (XG(lasttransid)) {
+ xdfree(XG(lasttransid));
+ XG(lasttransid) = NULL;
+ }
 
         xdebug_dbgp_cmdloop(context, 1 TSRMLS_CC);
 

[FILE: /xdebug/xdebug_var.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -r1.100 -r1.101
--- xdebug/xdebug_var.c:1.100 Sat Aug 22 10:18:06 2009 GMT
+++ xdebug/xdebug_var.c Sun Sep 06 20:03:27 2009 GMT
@@ -440,6 +440,7 @@
         xdebug_var_synopsis(&val, (xdebug_str*) &str, 1, debug_zval, options TSRMLS_CC);
 
         if (default_options) {
+ xdfree(options->runtime);
                 xdfree(options);
         }
 
@@ -735,7 +736,7 @@
                         } else {
                                 xdebug_xml_add_text_encodel(node, xdstrndup(Z_STRVAL_PP(struc), options->max_data), options->max_data);
                         }
- xdebug_xml_add_attribute(node, "size", xdebug_sprintf("%d", Z_STRLEN_PP(struc)));
+ xdebug_xml_add_attribute_ex(node, "size", xdebug_sprintf("%d", Z_STRLEN_PP(struc)), 0, 1);
                         break;
 
                 case IS_ARRAY:
@@ -833,7 +834,7 @@
                         full_name = xdstrdup(name);
                 }
                 xdebug_xml_add_attribute_ex(node, "name", xdstrdup(name), 0, 1);
- xdebug_xml_add_attribute_ex(node, "fullname", xdstrdup(full_name), 0, 1);
+ xdebug_xml_add_attribute_ex(node, "fullname", full_name, 0, 1);
         }
         xdebug_xml_add_attribute_ex(node, "address", xdebug_sprintf("%ld", (long) val), 0, 1);
         xdebug_var_export_xml_node(&val, name, node, options, 0 TSRMLS_CC);

[FILE: /xdebug/xdebug_xml.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- xdebug/xdebug_xml.c:1.14 Thu May 07 18:39:13 2009 GMT
+++ xdebug/xdebug_xml.c Sun Sep 06 20:03:27 2009 GMT
@@ -144,6 +144,16 @@
         xdfree(node);
 }
 
+inline void xdebug_xml_add_text(xdebug_xml_node *xml, char *text)
+{
+ return xdebug_xml_add_text_ex(xml, text, strlen(text), 1, 0);
+}
+
+inline void xdebug_xml_add_text_encode(xdebug_xml_node *xml, char *text)
+{
+ return xdebug_xml_add_text_ex(xml, text, strlen(text), 1, 1);
+}
+
 void xdebug_xml_add_text_ex(xdebug_xml_node *xml, char *text, int length, int free_text, int encode)
 {
         xdebug_xml_text_node *node = xdmalloc(sizeof (xdebug_xml_text_node));

[FILE: /xdebug/xdebug_xml.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- xdebug/xdebug_xml.h:1.7 Thu May 07 18:39:13 2009 GMT
+++ xdebug/xdebug_xml.h Sun Sep 06 20:03:27 2009 GMT
@@ -62,8 +62,8 @@
 void xdebug_xml_add_child(xdebug_xml_node *xml, xdebug_xml_node *child);
 
 void xdebug_xml_add_text_ex(xdebug_xml_node *xml, char *text, int length, int free_text, int encode);
-#define xdebug_xml_add_text(x,t) xdebug_xml_add_text_ex((x), (t), strlen(t), 1, 0)
-#define xdebug_xml_add_text_encode(x,t) xdebug_xml_add_text_ex((x), (t), strlen(t), 1, 1)
+void xdebug_xml_add_text(xdebug_xml_node *xml, char *text);
+void xdebug_xml_add_text_encode(xdebug_xml_node *xml, char *text);
 #define xdebug_xml_add_textl(x,t,l) xdebug_xml_add_text_ex((x), (t), (l), 1, 0)
 #define xdebug_xml_add_text_encodel(x,t,l) xdebug_xml_add_text_ex((x), (t), (l), 1, 1)
 
Received on Mon Sep 07 2009 - 00:09:30 BST

This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:03 BST