void* sspi_ContextBufferAlloc(UINT32 allocatorIndex, size_t size) { int index; void* contextBuffer; for (index = 0; index < (int) ContextBufferAllocTable.cMaxEntries; index++) { if (ContextBufferAllocTable.entries[index].contextBuffer == NULL) { contextBuffer = malloc(size); ZeroMemory(contextBuffer, size); ContextBufferAllocTable.cEntries++; ContextBufferAllocTable.entries[index].contextBuffer = contextBuffer; ContextBufferAllocTable.entries[index].allocatorIndex = allocatorIndex; return ContextBufferAllocTable.entries[index].contextBuffer; } } /* no available entry was found, the table needs to be grown */ sspi_ContextBufferAllocTableGrow(); /* the next call to sspi_ContextBufferAlloc() should now succeed */ return sspi_ContextBufferAlloc(allocatorIndex, size); }
static void* sspi_ContextBufferAlloc(UINT32 allocatorIndex, size_t size) { UINT32 index; void* contextBuffer; for (index = 0; index < ContextBufferAllocTable.cMaxEntries; index++) { if (!ContextBufferAllocTable.entries[index].contextBuffer) { contextBuffer = calloc(1, size); if (!contextBuffer) return NULL; ContextBufferAllocTable.cEntries++; ContextBufferAllocTable.entries[index].contextBuffer = contextBuffer; ContextBufferAllocTable.entries[index].allocatorIndex = allocatorIndex; return ContextBufferAllocTable.entries[index].contextBuffer; } } /* no available entry was found, the table needs to be grown */ if (sspi_ContextBufferAllocTableGrow() < 0) return NULL; /* the next call to sspi_ContextBufferAlloc() should now succeed */ return sspi_ContextBufferAlloc(allocatorIndex, size); }