#endif
}
+static inline void *
+gssalloc_realloc(void *value, size_t size)
+{
+#if _WIN32
+ return HeapReAlloc(GetProcessHeap(), 0, value, size);
+#else
+ return realloc(value, size);
+#endif
+}
+
static inline char *
gssalloc_strdup(const char *str)
{
{
gss_buffer_set_t set;
- set = (gss_buffer_set_desc *) malloc(sizeof(*set));
+ set = (gss_buffer_set_desc *) gssalloc_malloc(sizeof(*set));
if (set == GSS_C_NO_BUFFER_SET) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
set = *buffer_set;
- set->elements = (gss_buffer_desc *)realloc(set->elements,
+ set->elements = (gss_buffer_desc *)gssalloc_realloc(set->elements,
(set->count + 1) *
sizeof(gss_buffer_desc));
if (set->elements == NULL) {
p = &set->elements[set->count];
- p->value = malloc(member_buffer->length);
+ p->value = gssalloc_malloc(member_buffer->length);
if (p->value == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
if ((*buffer_set)->elements != NULL) {
- free((*buffer_set)->elements);
+ gssalloc_free((*buffer_set)->elements);
(*buffer_set)->elements = NULL;
}
(*buffer_set)->count = 0;
- free(*buffer_set);
+ gssalloc_free(*buffer_set);
*buffer_set = GSS_C_NO_BUFFER_SET;
return GSS_S_COMPLETE;
;
set->count = i;
- set->elements = calloc(i, sizeof(gss_buffer_desc));
+ set->elements = gssalloc_calloc(i, sizeof(gss_buffer_desc));
if (set->elements == NULL) {
gss_release_buffer_set(&minor_status, &set);
return ENOMEM;
}
- for (i = 0; i < set->count; i++) {
- set->elements[i].length = data[i].length;
- set->elements[i].value = data[i].data;
+ /*
+ * Copy last element first so data remains properly
+ * NULL-terminated in case of allocation failure
+ * in data_to_gss() on windows.
+ */
+ for (i = set->count-1; i >= 0; i--) {
+ if (data_to_gss(&data[i], &set->elements[i])) {
+ gss_release_buffer_set(&minor_status, &set);
+ return ENOMEM;
+ }
}
free(data);