[freetds] [PATCH] ctlib: ct_param memory leaks, stored proc return status

Iain Calder iain.calder at blueyonder.co.uk
Mon Apr 12 18:48:06 EDT 2004


I have posted this patch before but it does not seem to have made it 
into production.  Thanks to Bill Thompson for help with the return 
status fix.

Diff is against latest snapshot.


--- freetds-0.63.dev.20040412/src/ctlib/ct.c    2004-02-03 
19:28:10.000000000 +0000
+++ freetds-0.63.dev.20040412.new/src/ctlib/ct.c    2004-04-12 
23:31:26.000000000 +0100
@@ -1462,6 +1462,12 @@
             free(cmd->query);
         if (cmd->input_params)
             param_clear(cmd->input_params);
+        if (cmd->rpc) {
+            if (cmd->rpc->param_list)
+                param_clear(cmd->rpc->param_list);
+            free(cmd->rpc->name);
+            free(cmd->rpc);
+        }
         free(cmd);
     }
     return CS_SUCCEED;
@@ -2674,16 +2680,14 @@
         rpc = cmd->rpc;
         pparam = &rpc->param_list;
         if (*pparam == NULL) {
-            *pparam = (CSREMOTE_PROC_PARAM *) 
malloc(sizeof(CSREMOTE_PROC_PARAM));
+            *pparam = param;
         } else {
             while ((*pparam)->next != NULL) {
                 pparam = &(*pparam)->next;
             }
-
-            (*pparam)->next = (CSREMOTE_PROC_PARAM *) 
malloc(sizeof(CSREMOTE_PROC_PARAM));
-            pparam = &(*pparam)->next;
         }
-        *pparam = param;
+        (*pparam)->next = param;
+        pparam = &(*pparam)->next;
         (*pparam)->next = NULL;
         tdsdump_log(TDS_DBG_INFO1, " ct_param() added rpc parameter %s 
\n", (*param).name);
         return CS_SUCCEED;
@@ -3171,11 +3175,13 @@
 {
     TDSRESULTINFO *info;
     TDSCOLUMN *curcol;
+    TDS_INT saved_status;
 
     enum
     { num_cols = 1 };
 
     assert(tds);
+    saved_status = tds->ret_status;
     tds_free_all_results(tds);
 
     /* allocate the columns structure */
@@ -3202,7 +3208,7 @@
 
     assert(0 <= curcol->column_offset && curcol->column_offset < 
info->row_size);
 
-    *(TDS_INT *) (info->current_row + curcol->column_offset) = 
tds->ret_status;
+    *(TDS_INT *) (info->current_row + curcol->column_offset) = 
saved_status;
 
     return TDS_SUCCEED;
 }



More information about the FreeTDS mailing list