Attached is a patch for a small memory leak in trousers-0.3.4, I tested the 
build on
both Solaris and Linux (Ubuntu).

-Signed off by Wyllys Ingersoll


--- src/tspi/rpc/hosttable.c.orig       Wed Mar 10 11:43:02 2010
+++ src/tspi/rpc/hosttable.c    Wed Mar 10 11:46:24 2010
@@ -34,6 +34,7 @@
 
        return TSS_SUCCESS;
 }
+
 #ifdef SOLARIS
 #pragma init(_init)
 void _init(void)
@@ -45,7 +46,6 @@
        __tspi_obj_list_init();
 }
 
-#if 0
 void
 host_table_final()
 {
@@ -56,6 +56,10 @@
        for (hte = ht->entries; hte; hte = next) {
                if (hte)
                        next = hte->next;
+               if (hte->hostname)
+                       free(hte->hostname);
+               if (hte->comm.buf)
+                       free(hte->comm.buf);
                free(hte);
        }
 
@@ -65,11 +69,15 @@
        ht = NULL;
 }
 
+#ifdef SOLARIS
+#pragma fini(_fini)
+void _fini(void)
+#else
 void __attribute__ ((destructor)) my_fini(void)
+#endif
 {
        host_table_final();
 }
-#endif
 
 TSS_RESULT
 __tspi_add_table_entry(TSS_HCONTEXT tspContext, BYTE *host, int type, struct 
host_table_entry **ret)
@@ -100,6 +108,7 @@
                if (tmp->tspContext == tspContext) {
                        LogError("Tspi_Context_Connect attempted on an already 
connected context!");
                        MUTEX_UNLOCK(ht->lock);
+                       free(entry->hostname);
                        free(entry->comm.buf);
                        free(entry);
                        return TSPERR(TSS_E_CONNECTION_FAILED);
@@ -133,6 +142,8 @@
                                prev->next = hte->next;
                        else
                                ht->entries = hte->next;
+                       if (hte->hostname)
+                               free(hte->hostname);
                        free(hte->comm.buf);
                        free(hte);
                        break;
--- src/tspi/obj_context.c.orig Wed Feb  3 07:38:56 2010
+++ src/tspi/obj_context.c      Wed Feb  3 07:41:22 2010
@@ -187,7 +187,11 @@
                *data = NULL;
                *size = 0;
        } else {
-               *data = calloc_tspi(obj->tspContext, 
context->machineNameLength);
+               /*
+                * Don't use calloc_tspi because this memory is
+                * not freed using "free_tspi"
+                */
+               *data = calloc(1, context->machineNameLength);
                if (*data == NULL) {
                        LogError("malloc of %u bytes failed.",
                                        context->machineNameLength);
--- src/tspi/tsp_context_mem.c.orig     Wed Feb  3 07:39:00 2010
+++ src/tspi/tsp_context_mem.c  Wed Feb  3 07:39:16 2010
@@ -21,6 +21,22 @@
 #include "tsplog.h"
 #include "obj.h"
 
+static struct memTable *
+__tspi_createTable()
+{
+       struct memTable *table = NULL;
+       /*
+        * No table has yet been created to hold the memory allocations of
+        * this context, so we need to create one
+        */
+       table = calloc(1, sizeof(struct memTable));
+       if (table == NULL) {
+               LogError("malloc of %zd bytes failed.", sizeof(struct 
memTable));
+               return NULL;
+       }
+       return (table);
+}
+
 /* caller needs to lock memtable lock */
 struct memTable *
 getTable(TSS_HCONTEXT tspContext)
@@ -34,6 +50,26 @@
        return NULL;
 }
 
+/* caller needs to lock memtable lock */
+static void
+__tspi_addTable(struct memTable *new)
+{
+       struct memTable *tmp = SpiMemoryTable;
+
+       /* base case, this is the first table */
+       if (SpiMemoryTable == NULL) {
+               SpiMemoryTable = new;
+               return;
+       }
+
+       /* else add @new onto the end */
+       for (; tmp; tmp = tmp->nextTable)
+               if (tmp->nextTable == NULL) {
+                       tmp->nextTable = new;
+                       break;
+               }
+}
+
 /* caller needs to lock memtable lock and be sure the context mem slot for
  * @tspContext exists before calling.
  */
@@ -41,8 +77,17 @@
 __tspi_addEntry(TSS_HCONTEXT tspContext, struct memEntry *new)
 {
        struct memTable *tmp = getTable(tspContext);
-       struct memEntry *tmp_entry = tmp->entries;
+       struct memEntry *tmp_entry;
 
+       if (tmp == NULL) {
+               if ((tmp = __tspi_createTable()) == NULL)
+                       return;
+               tmp->tspContext = tspContext;
+               __tspi_addTable(tmp);
+       }
+
+       tmp_entry = tmp->entries;
+
        if (tmp->entries == NULL) {
                tmp->entries = new;
                return;
@@ -58,26 +103,6 @@
 }
 
 /* caller needs to lock memtable lock */
-void
-__tspi_addTable(struct memTable *new)
-{
-       struct memTable *tmp = SpiMemoryTable;
-
-       /* base case, this is the first table */
-       if (SpiMemoryTable == NULL) {
-               SpiMemoryTable = new;
-               return;
-       }
-
-       /* else add @new onto the end */
-       for (; tmp; tmp = tmp->nextTable)
-               if (tmp->nextTable == NULL) {
-                       tmp->nextTable = new;
-                       break;
-               }
-}
-
-/* caller needs to lock memtable lock */
 TSS_RESULT
 __tspi_freeTable(TSS_HCONTEXT tspContext)
 {
@@ -166,12 +191,7 @@
 
        table = getTable(tspContext);
        if (table == NULL) {
-               /* no table has yet been created to hold the memory allocations 
of
-                * this context, so we need to create one
-                */
-               table = calloc(1, sizeof(struct memTable));
-               if (table == NULL) {
-                       LogError("malloc of %zd bytes failed.", sizeof(struct 
memTable));
+               if ((table = __tspi_createTable()) == NULL) {
                        MUTEX_UNLOCK(memtable_lock);
                        return NULL;
                }
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
TrouSerS-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/trousers-tech

Reply via email to