Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Unified Diff: src/tspi/tsp_context_mem.c

Issue 3581012: Upgrade from trousers 0.3.3 to 0.3.6 and from testsuite 0.2 to 0.3. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/trousers.git
Patch Set: git cl push Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/tspi/tsp_auth.c ('k') | src/tspi/tsp_maint.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/tspi/tsp_context_mem.c
diff --git a/src/tspi/tsp_context_mem.c b/src/tspi/tsp_context_mem.c
index b1993bc6f911ffd5450f4ee148fdc28985bbb79a..13f1243dd3b6ce31d068db3ffa8ec33385e21f70 100644
--- a/src/tspi/tsp_context_mem.c
+++ b/src/tspi/tsp_context_mem.c
@@ -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 @@ getTable(TSS_HCONTEXT tspContext)
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,7 +77,16 @@ void
__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;
@@ -58,26 +103,6 @@ __tspi_addEntry(TSS_HCONTEXT tspContext, struct memEntry *new)
}
/* 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 @@ calloc_tspi(TSS_HCONTEXT tspContext, UINT32 howMuch)
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;
}
« no previous file with comments | « src/tspi/tsp_auth.c ('k') | src/tspi/tsp_maint.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698