2012-05-10 18:10:03 +04:00
|
|
|
/*
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-01 02:24:37 +04:00
|
|
|
* Memory Utils
|
|
|
|
*
|
|
|
|
* Copyright 2009-2011 Jay Sorg
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-07-01 02:24:37 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-10-09 07:42:01 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2011-07-01 02:24:37 +04:00
|
|
|
#include <freerdp/utils/memory.h>
|
|
|
|
|
2011-07-03 20:42:35 +04:00
|
|
|
/**
|
|
|
|
* Allocate memory initialized to zero.
|
2012-05-10 18:10:03 +04:00
|
|
|
* This function is used to secure a calloc call.
|
|
|
|
* It verifies its return value, and logs an error if the allocation failed.
|
|
|
|
*
|
|
|
|
* @param size - number of bytes to allocate. If the size is < 1, it will default to 1.
|
|
|
|
*
|
|
|
|
* @return a pointer to the allocated and zeroed buffer. NULL if the allocation failed.
|
2011-07-03 20:42:35 +04:00
|
|
|
*/
|
2011-07-13 18:13:00 +04:00
|
|
|
void* xzalloc(size_t size)
|
2011-07-03 20:42:35 +04:00
|
|
|
{
|
2011-07-13 18:13:00 +04:00
|
|
|
void* mem;
|
2011-07-03 20:42:35 +04:00
|
|
|
|
|
|
|
if (size < 1)
|
|
|
|
size = 1;
|
|
|
|
|
|
|
|
mem = calloc(1, size);
|
|
|
|
|
|
|
|
if (mem == NULL)
|
2012-01-31 07:46:02 +04:00
|
|
|
{
|
2011-07-03 20:42:35 +04:00
|
|
|
perror("xzalloc");
|
2012-02-10 05:32:08 +04:00
|
|
|
printf("xzalloc: failed to allocate memory of size: %d\n", (int) size);
|
2012-01-31 07:46:02 +04:00
|
|
|
}
|
2011-07-03 20:42:35 +04:00
|
|
|
|
2011-07-01 02:24:37 +04:00
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|