forked from Telodendria/Telodendria
Use new Memory API for all memory allocations.
This commit is contained in:
parent
945acd1adf
commit
8cb86e8f67
14 changed files with 141 additions and 119 deletions
16
src/Array.c
16
src/Array.c
|
@ -28,7 +28,7 @@
|
|||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <Memory.h>
|
||||
|
||||
struct Array
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ ArrayAdd(Array * array, void *value)
|
|||
Array *
|
||||
ArrayCreate(void)
|
||||
{
|
||||
Array *array = malloc(sizeof(Array));
|
||||
Array *array = Malloc(sizeof(Array));
|
||||
|
||||
if (!array)
|
||||
{
|
||||
|
@ -61,11 +61,11 @@ ArrayCreate(void)
|
|||
|
||||
array->size = 0;
|
||||
array->allocated = ARRAY_BLOCK;
|
||||
array->entries = malloc(sizeof(void *) * ARRAY_BLOCK);
|
||||
array->entries = Malloc(sizeof(void *) * ARRAY_BLOCK);
|
||||
|
||||
if (!array->entries)
|
||||
{
|
||||
free(array);
|
||||
Free(array);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -100,8 +100,8 @@ ArrayFree(Array * array)
|
|||
{
|
||||
if (array)
|
||||
{
|
||||
free(array->entries);
|
||||
free(array);
|
||||
Free(array->entries);
|
||||
Free(array);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ ArrayInsert(Array * array, void *value, size_t index)
|
|||
|
||||
tmp = array->entries;
|
||||
|
||||
array->entries = realloc(array->entries,
|
||||
array->entries = Realloc(array->entries,
|
||||
sizeof(void *) * newSize);
|
||||
|
||||
if (!array->entries)
|
||||
|
@ -186,7 +186,7 @@ ArrayTrim(Array * array)
|
|||
|
||||
tmp = array->entries;
|
||||
|
||||
array->entries = realloc(array->entries,
|
||||
array->entries = Realloc(array->entries,
|
||||
sizeof(void *) * array->size);
|
||||
|
||||
if (!array->entries)
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
#include <Base64.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <Memory.h>
|
||||
|
||||
static const char Base64EncodeMap[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
@ -94,7 +94,7 @@ Base64Encode(const char *input, size_t len)
|
|||
}
|
||||
|
||||
outLen = Base64EncodedSize(len);
|
||||
out = malloc(outLen + 1);
|
||||
out = Malloc(outLen + 1);
|
||||
if (!out)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -171,7 +171,7 @@ Base64Decode(const char *input, size_t len)
|
|||
}
|
||||
}
|
||||
|
||||
out = malloc(outLen + 1);
|
||||
out = Malloc(outLen + 1);
|
||||
if (!out)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -226,7 +226,7 @@ Base64Pad(char **base64Ptr, size_t length)
|
|||
|
||||
newSize = length + (4 - (length % 4));
|
||||
|
||||
tmp = realloc(*base64Ptr, newSize + 100);;
|
||||
tmp = Realloc(*base64Ptr, newSize + 100);;
|
||||
if (!tmp)
|
||||
{
|
||||
return 0; /* Memory error */
|
||||
|
|
44
src/Config.c
44
src/Config.c
|
@ -23,6 +23,8 @@
|
|||
*/
|
||||
#include <Config.h>
|
||||
|
||||
#include <Memory.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
@ -99,7 +101,7 @@ ConfigParseResultFree(ConfigParseResult * result)
|
|||
* Note that if the parse was valid, the hash map
|
||||
* needs to be freed separately.
|
||||
*/
|
||||
free(result);
|
||||
Free(result);
|
||||
}
|
||||
|
||||
Array *
|
||||
|
@ -126,14 +128,14 @@ ConfigDirectiveFree(ConfigDirective * directive)
|
|||
|
||||
for (i = 0; i < ArraySize(directive->values); i++)
|
||||
{
|
||||
free(ArrayGet(directive->values, i));
|
||||
Free(ArrayGet(directive->values, i));
|
||||
}
|
||||
|
||||
ArrayFree(directive->values);
|
||||
|
||||
ConfigFree(directive->children);
|
||||
|
||||
free(directive);
|
||||
Free(directive);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -145,7 +147,7 @@ ConfigFree(HashMap * conf)
|
|||
while (HashMapIterate(conf, &key, &value))
|
||||
{
|
||||
ConfigDirectiveFree((ConfigDirective *) value);
|
||||
free(key);
|
||||
Free(key);
|
||||
}
|
||||
|
||||
HashMapFree(conf);
|
||||
|
@ -154,7 +156,7 @@ ConfigFree(HashMap * conf)
|
|||
static ConfigParserState *
|
||||
ConfigParserStateCreate(FILE * stream)
|
||||
{
|
||||
ConfigParserState *state = malloc(sizeof(ConfigParserState));
|
||||
ConfigParserState *state = Malloc(sizeof(ConfigParserState));
|
||||
|
||||
if (!state)
|
||||
{
|
||||
|
@ -165,7 +167,7 @@ ConfigParserStateCreate(FILE * stream)
|
|||
|
||||
if (!state->macroMap)
|
||||
{
|
||||
free(state);
|
||||
Free(state);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -191,17 +193,17 @@ ConfigParserStateFree(ConfigParserState * state)
|
|||
}
|
||||
|
||||
|
||||
free(state->token);
|
||||
Free(state->token);
|
||||
|
||||
while (HashMapIterate(state->macroMap, &key, &value))
|
||||
{
|
||||
free(key);
|
||||
free(value);
|
||||
Free(key);
|
||||
Free(value);
|
||||
}
|
||||
|
||||
HashMapFree(state->macroMap);
|
||||
|
||||
free(state);
|
||||
Free(state);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -265,7 +267,7 @@ ConfigTokenSeek(ConfigParserState * state)
|
|||
if (!state->token)
|
||||
{
|
||||
state->tokenSize = CONFIG_BUFFER_BLOCK;
|
||||
state->token = malloc(CONFIG_BUFFER_BLOCK);
|
||||
state->token = Malloc(CONFIG_BUFFER_BLOCK);
|
||||
}
|
||||
state->token[state->tokenLen] = c;
|
||||
state->tokenLen++;
|
||||
|
@ -278,7 +280,7 @@ ConfigTokenSeek(ConfigParserState * state)
|
|||
if (state->tokenLen >= state->tokenSize)
|
||||
{
|
||||
state->tokenSize += CONFIG_BUFFER_BLOCK;
|
||||
state->token = realloc(state->token,
|
||||
state->token = Realloc(state->token,
|
||||
state->tokenSize);
|
||||
}
|
||||
}
|
||||
|
@ -334,7 +336,7 @@ ConfigTokenSeek(ConfigParserState * state)
|
|||
if (state->tokenLen >= state->tokenSize)
|
||||
{
|
||||
state->tokenSize += CONFIG_BUFFER_BLOCK;
|
||||
state->token = realloc(state->token,
|
||||
state->token = Realloc(state->token,
|
||||
state->tokenSize);
|
||||
}
|
||||
}
|
||||
|
@ -361,7 +363,7 @@ ConfigTokenSeek(ConfigParserState * state)
|
|||
if (state->tokenLen >= state->tokenSize)
|
||||
{
|
||||
state->tokenSize += CONFIG_BUFFER_BLOCK;
|
||||
state->token = realloc(state->token,
|
||||
state->token = Realloc(state->token,
|
||||
state->tokenSize);
|
||||
}
|
||||
}
|
||||
|
@ -381,7 +383,7 @@ ConfigTokenSeek(ConfigParserState * state)
|
|||
if (state->tokenLen)
|
||||
{
|
||||
state->tokenSize = state->tokenLen;
|
||||
state->token = realloc(state->token, state->tokenSize);
|
||||
state->token = Realloc(state->token, state->tokenSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,7 +403,7 @@ ConfigParseBlock(ConfigParserState * state, int level)
|
|||
|
||||
while (ConfigExpect(state, TOKEN_NAME))
|
||||
{
|
||||
char *name = malloc(state->tokenLen + 1);
|
||||
char *name = Malloc(state->tokenLen + 1);
|
||||
|
||||
strcpy(name, state->token);
|
||||
|
||||
|
@ -410,7 +412,7 @@ ConfigParseBlock(ConfigParserState * state, int level)
|
|||
{
|
||||
ConfigDirective *directive;
|
||||
|
||||
directive = malloc(sizeof(ConfigDirective));
|
||||
directive = Malloc(sizeof(ConfigDirective));
|
||||
directive->children = NULL;
|
||||
directive->values = ArrayCreate();
|
||||
|
||||
|
@ -440,7 +442,7 @@ ConfigParseBlock(ConfigParserState * state, int level)
|
|||
|
||||
/* dval is a pointer which is overwritten with the next
|
||||
* token. */
|
||||
dvalCpy = malloc(strlen(dval) + 1);
|
||||
dvalCpy = Malloc(strlen(dval) + 1);
|
||||
strcpy(dvalCpy, dval);
|
||||
|
||||
ArrayAdd(directive->values, dvalCpy);
|
||||
|
@ -473,10 +475,10 @@ ConfigParseBlock(ConfigParserState * state, int level)
|
|||
ConfigTokenSeek(state);
|
||||
if (ConfigExpect(state, TOKEN_VALUE))
|
||||
{
|
||||
char *valueCopy = malloc(strlen(state->token) + 1);
|
||||
char *valueCopy = Malloc(strlen(state->token) + 1);
|
||||
|
||||
strcpy(valueCopy, state->token);
|
||||
free(HashMapSet(state->macroMap, name, valueCopy));
|
||||
Free(HashMapSet(state->macroMap, name, valueCopy));
|
||||
ConfigTokenSeek(state);
|
||||
}
|
||||
else
|
||||
|
@ -522,7 +524,7 @@ ConfigParse(FILE * stream)
|
|||
HashMap *conf;
|
||||
ConfigParserState *state;
|
||||
|
||||
result = malloc(sizeof(ConfigParseResult));
|
||||
result = Malloc(sizeof(ConfigParseResult));
|
||||
state = ConfigParserStateCreate(stream);
|
||||
conf = ConfigParseBlock(state, 0);
|
||||
|
||||
|
|
|
@ -23,8 +23,10 @@
|
|||
*/
|
||||
#include <HashMap.h>
|
||||
|
||||
#include <Memory.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct HashMapBucket
|
||||
{
|
||||
|
@ -77,12 +79,14 @@ HashMapGrow(HashMap * map)
|
|||
oldCapacity = map->capacity;
|
||||
map->capacity *= 2;
|
||||
|
||||
newEntries = calloc(map->capacity, sizeof(HashMapBucket *));
|
||||
newEntries = Malloc(map->capacity * sizeof(HashMapBucket *));
|
||||
if (!newEntries)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&newEntries, 0, map->capacity * sizeof(HashMapBucket *));
|
||||
|
||||
for (i = 0; i < oldCapacity; i++)
|
||||
{
|
||||
/* If there is a value here, and it isn't a tombstone */
|
||||
|
@ -97,7 +101,7 @@ HashMapGrow(HashMap * map)
|
|||
{
|
||||
if (!newEntries[index]->hash)
|
||||
{
|
||||
free(newEntries[index]);
|
||||
Free(newEntries[index]);
|
||||
newEntries[index] = map->entries[i];
|
||||
break;
|
||||
}
|
||||
|
@ -114,11 +118,11 @@ HashMapGrow(HashMap * map)
|
|||
else
|
||||
{
|
||||
/* Either NULL or a tombstone */
|
||||
free(map->entries[i]);
|
||||
Free(map->entries[i]);
|
||||
}
|
||||
}
|
||||
|
||||
free(map->entries);
|
||||
Free(map->entries);
|
||||
map->entries = newEntries;
|
||||
return 1;
|
||||
}
|
||||
|
@ -126,7 +130,7 @@ HashMapGrow(HashMap * map)
|
|||
HashMap *
|
||||
HashMapCreate(void)
|
||||
{
|
||||
HashMap *map = malloc(sizeof(HashMap));
|
||||
HashMap *map = Malloc(sizeof(HashMap));
|
||||
|
||||
if (!map)
|
||||
{
|
||||
|
@ -139,13 +143,15 @@ HashMapCreate(void)
|
|||
map->iterator = 0;
|
||||
map->hashFunc = HashMapHashKey;
|
||||
|
||||
map->entries = calloc(map->capacity, sizeof(HashMapBucket *));
|
||||
map->entries = Malloc(map->capacity * sizeof(HashMapBucket *));
|
||||
if (!map->entries)
|
||||
{
|
||||
free(map);
|
||||
Free(map);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(map->entries, 0, map->capacity * sizeof(HashMapBucket *));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -195,11 +201,11 @@ HashMapFree(HashMap * map)
|
|||
{
|
||||
if (map->entries[i])
|
||||
{
|
||||
free(map->entries[i]);
|
||||
Free(map->entries[i]);
|
||||
}
|
||||
}
|
||||
free(map->entries);
|
||||
free(map);
|
||||
Free(map->entries);
|
||||
Free(map);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -318,7 +324,7 @@ HashMapSet(HashMap * map, char *key, void *value)
|
|||
|
||||
if (!bucket)
|
||||
{
|
||||
bucket = malloc(sizeof(HashMapBucket));
|
||||
bucket = Malloc(sizeof(HashMapBucket));
|
||||
if (!bucket)
|
||||
{
|
||||
break;
|
||||
|
@ -359,11 +365,11 @@ HashMapIterateFree(char *key, void *value)
|
|||
{
|
||||
if (key)
|
||||
{
|
||||
free(key);
|
||||
Free(key);
|
||||
}
|
||||
|
||||
if (value)
|
||||
{
|
||||
free(value);
|
||||
Free(value);
|
||||
}
|
||||
}
|
||||
|
|
15
src/Http.c
15
src/Http.c
|
@ -27,6 +27,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Memory.h>
|
||||
#include <Constants.h>
|
||||
#include <HashMap.h>
|
||||
|
||||
|
@ -231,7 +232,7 @@ HttpUrlEncode(char *str)
|
|||
|
||||
size = TELODENDRIA_STRING_CHUNK;
|
||||
len = 0;
|
||||
encoded = malloc(size);
|
||||
encoded = Malloc(size);
|
||||
if (!encoded)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -246,10 +247,10 @@ HttpUrlEncode(char *str)
|
|||
char *tmp;
|
||||
|
||||
size += TELODENDRIA_STRING_CHUNK;
|
||||
tmp = realloc(encoded, size);
|
||||
tmp = Realloc(encoded, size);
|
||||
if (!tmp)
|
||||
{
|
||||
free(encoded);
|
||||
Free(encoded);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -326,7 +327,7 @@ HttpUrlDecode(char *str)
|
|||
|
||||
i = 0;
|
||||
inputLen = strlen(str);
|
||||
decoded = malloc(inputLen);
|
||||
decoded = Malloc(inputLen);
|
||||
|
||||
if (!decoded)
|
||||
{
|
||||
|
@ -346,7 +347,7 @@ HttpUrlDecode(char *str)
|
|||
if (sscanf(str, "%2X", &d) != 1)
|
||||
{
|
||||
/* Decoding error */
|
||||
free(decoded);
|
||||
Free(decoded);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -407,7 +408,7 @@ HttpParamEncode(HashMap * params, FILE * out)
|
|||
|
||||
fprintf(out, "%s=%s&", encKey, encVal);
|
||||
|
||||
free(encKey);
|
||||
free(encVal);
|
||||
Free(encKey);
|
||||
Free(encVal);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <NonPosix.h>
|
||||
|
||||
#include <HttpServer.h>
|
||||
#include <Memory.h>
|
||||
#include <Queue.h>
|
||||
#include <Array.h>
|
||||
#include <Util.h>
|
||||
|
@ -78,7 +79,7 @@ HttpServerContextCreate(HttpRequestMethod requestMethod,
|
|||
{
|
||||
HttpServerContext *c;
|
||||
|
||||
c = malloc(sizeof(HttpServerContext));
|
||||
c = Malloc(sizeof(HttpServerContext));
|
||||
if (!c)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -87,15 +88,15 @@ HttpServerContextCreate(HttpRequestMethod requestMethod,
|
|||
c->requestHeaders = HashMapCreate();
|
||||
if (!c->requestHeaders)
|
||||
{
|
||||
free(c);
|
||||
Free(c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
c->responseHeaders = HashMapCreate();
|
||||
if (!c->responseHeaders)
|
||||
{
|
||||
free(c->requestHeaders);
|
||||
free(c);
|
||||
Free(c->requestHeaders);
|
||||
Free(c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -120,15 +121,15 @@ HttpServerContextFree(HttpServerContext * c)
|
|||
|
||||
while (HashMapIterate(c->requestHeaders, &key, &val))
|
||||
{
|
||||
free(key);
|
||||
free(val);
|
||||
Free(key);
|
||||
Free(val);
|
||||
}
|
||||
HashMapFree(c->requestHeaders);
|
||||
|
||||
/* It is up to the handler to free its values */
|
||||
HashMapFree(c->responseHeaders);
|
||||
|
||||
free(c->requestPath);
|
||||
Free(c->requestPath);
|
||||
fclose(c->stream);
|
||||
}
|
||||
|
||||
|
@ -277,12 +278,14 @@ HttpServerCreate(unsigned short port, unsigned int nThreads, unsigned int maxCon
|
|||
return NULL;
|
||||
}
|
||||
|
||||
server = calloc(1, sizeof(HttpServer));
|
||||
server = Malloc(sizeof(HttpServer));
|
||||
if (!server)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
memset(server, 0, sizeof(HttpServer));
|
||||
|
||||
server->threadPool = ArrayCreate();
|
||||
if (!server->threadPool)
|
||||
{
|
||||
|
@ -350,7 +353,7 @@ error:
|
|||
close(server->sd);
|
||||
}
|
||||
|
||||
free(server);
|
||||
Free(server);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -367,7 +370,7 @@ HttpServerFree(HttpServer * server)
|
|||
QueueFree(server->connQueue);
|
||||
pthread_mutex_destroy(&server->connQueueMutex);
|
||||
ArrayFree(server->threadPool);
|
||||
free(server);
|
||||
Free(server);
|
||||
}
|
||||
|
||||
static void *
|
||||
|
@ -440,7 +443,7 @@ HttpServerWorkerThread(void *args)
|
|||
}
|
||||
}
|
||||
|
||||
requestPath = malloc((i * sizeof(char)) + 1);
|
||||
requestPath = Malloc((i * sizeof(char)) + 1);
|
||||
strcpy(requestPath, pathPtr);
|
||||
|
||||
requestProtocol = &pathPtr[i + 1];
|
||||
|
@ -481,7 +484,7 @@ HttpServerWorkerThread(void *args)
|
|||
line[i] = tolower(line[i]);
|
||||
}
|
||||
|
||||
headerKey = malloc((i * sizeof(char)) + 1);
|
||||
headerKey = Malloc((i * sizeof(char)) + 1);
|
||||
if (!headerKey)
|
||||
{
|
||||
goto internal_error;
|
||||
|
@ -505,7 +508,7 @@ HttpServerWorkerThread(void *args)
|
|||
line[i] = '\0';
|
||||
}
|
||||
|
||||
headerValue = malloc(strlen(headerPtr) + 1);
|
||||
headerValue = Malloc(strlen(headerPtr) + 1);
|
||||
if (!headerValue)
|
||||
{
|
||||
goto internal_error;
|
||||
|
@ -532,7 +535,7 @@ bad_request:
|
|||
goto finish;
|
||||
|
||||
finish:
|
||||
free(line);
|
||||
Free(line);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
@ -555,7 +558,7 @@ HttpServerEventThread(void *args)
|
|||
|
||||
for (i = 0; i < server->nThreads; i++)
|
||||
{
|
||||
pthread_t *workerThread = malloc(sizeof(pthread_t));
|
||||
pthread_t *workerThread = Malloc(sizeof(pthread_t));
|
||||
|
||||
if (!workerThread)
|
||||
{
|
||||
|
@ -604,7 +607,7 @@ HttpServerEventThread(void *args)
|
|||
pthread_t *workerThread = ArrayGet(server->threadPool, i);
|
||||
|
||||
pthread_join(*workerThread, NULL);
|
||||
free(workerThread);
|
||||
Free(workerThread);
|
||||
}
|
||||
|
||||
while ((fp = DequeueConnection(server)))
|
||||
|
|
37
src/Json.c
37
src/Json.c
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
#include <Json.h>
|
||||
|
||||
#include <Memory.h>
|
||||
#include <Util.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -85,7 +86,7 @@ JsonValueType(JsonValue * value)
|
|||
static JsonValue *
|
||||
JsonValueAllocate(void)
|
||||
{
|
||||
return malloc(sizeof(JsonValue));
|
||||
return Malloc(sizeof(JsonValue));
|
||||
}
|
||||
|
||||
JsonValue *
|
||||
|
@ -315,13 +316,13 @@ JsonValueFree(JsonValue * value)
|
|||
ArrayFree(arr);
|
||||
break;
|
||||
case JSON_STRING:
|
||||
free(value->as.string);
|
||||
Free(value->as.string);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
free(value);
|
||||
Free(value);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -405,7 +406,7 @@ JsonDecodeString(FILE * in)
|
|||
len = 0;
|
||||
allocated = strBlockSize;
|
||||
|
||||
str = malloc(allocated * sizeof(char));
|
||||
str = Malloc(allocated * sizeof(char));
|
||||
if (!str)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -416,7 +417,7 @@ JsonDecodeString(FILE * in)
|
|||
if (c <= 0x001F)
|
||||
{
|
||||
/* Bad byte; these must be escaped */
|
||||
free(str);
|
||||
Free(str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -461,7 +462,7 @@ JsonDecodeString(FILE * in)
|
|||
if (fscanf(in, "%04lx", &utf8) != 1)
|
||||
{
|
||||
/* Bad hex value */
|
||||
free(str);
|
||||
Free(str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -489,18 +490,18 @@ JsonDecodeString(FILE * in)
|
|||
if (!utf8Ptr)
|
||||
{
|
||||
/* Mem error */
|
||||
free(str);
|
||||
Free(str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Move the output of UtilUtf8Encode() into our
|
||||
* local buffer */
|
||||
strcpy(a, utf8Ptr);
|
||||
free(utf8Ptr);
|
||||
Free(utf8Ptr);
|
||||
break;
|
||||
default:
|
||||
/* Bad escape value */
|
||||
free(str);
|
||||
Free(str);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
|
@ -519,10 +520,10 @@ JsonDecodeString(FILE * in)
|
|||
char *tmp;
|
||||
|
||||
allocated += strBlockSize;
|
||||
tmp = realloc(str, allocated * sizeof(char));
|
||||
tmp = Realloc(str, allocated * sizeof(char));
|
||||
if (!tmp)
|
||||
{
|
||||
free(str);
|
||||
Free(str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -535,7 +536,7 @@ JsonDecodeString(FILE * in)
|
|||
}
|
||||
}
|
||||
|
||||
free(str);
|
||||
Free(str);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -673,7 +674,7 @@ JsonTokenSeek(JsonParserState * state)
|
|||
|
||||
if (state->token)
|
||||
{
|
||||
free(state->token);
|
||||
Free(state->token);
|
||||
state->token = NULL;
|
||||
}
|
||||
|
||||
|
@ -713,7 +714,7 @@ JsonTokenSeek(JsonParserState * state)
|
|||
size_t allocated = 16;
|
||||
|
||||
state->tokenLen = 1;
|
||||
state->token = malloc(allocated);
|
||||
state->token = Malloc(allocated);
|
||||
if (!state->token)
|
||||
{
|
||||
state->tokenType = TOKEN_EOF;
|
||||
|
@ -748,7 +749,7 @@ JsonTokenSeek(JsonParserState * state)
|
|||
|
||||
allocated += 16;
|
||||
|
||||
tmp = realloc(state->token, allocated);
|
||||
tmp = Realloc(state->token, allocated);
|
||||
if (!tmp)
|
||||
{
|
||||
state->tokenType = TOKEN_EOF;
|
||||
|
@ -781,7 +782,7 @@ JsonTokenSeek(JsonParserState * state)
|
|||
else
|
||||
{
|
||||
state->tokenLen = 8;
|
||||
state->token = malloc(state->tokenLen);
|
||||
state->token = Malloc(state->tokenLen);
|
||||
if (!state->token)
|
||||
{
|
||||
state->tokenType = TOKEN_EOF;
|
||||
|
@ -875,7 +876,7 @@ JsonDecodeValue(JsonParserState * state)
|
|||
value = JsonValueArray(JsonDecodeArray(state));
|
||||
break;
|
||||
case TOKEN_STRING:
|
||||
strValue = malloc(state->tokenLen);
|
||||
strValue = Malloc(state->tokenLen);
|
||||
if (!strValue)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -919,7 +920,7 @@ JsonDecodeObject(JsonParserState * state)
|
|||
JsonTokenSeek(state);
|
||||
if (JsonExpect(state, TOKEN_STRING))
|
||||
{
|
||||
char *key = malloc(state->tokenLen);
|
||||
char *key = Malloc(state->tokenLen);
|
||||
JsonValue *value;
|
||||
|
||||
if (!key)
|
||||
|
|
10
src/Log.c
10
src/Log.c
|
@ -23,7 +23,9 @@
|
|||
*/
|
||||
#include <Log.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <Memory.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
@ -48,13 +50,15 @@ LogConfigCreate(void)
|
|||
{
|
||||
LogConfig *config;
|
||||
|
||||
config = calloc(1, sizeof(LogConfig));
|
||||
config = Malloc(sizeof(LogConfig));
|
||||
|
||||
if (!config)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(config, 0, sizeof(LogConfig));
|
||||
|
||||
LogConfigLevelSet(config, LOG_MESSAGE);
|
||||
LogConfigIndentSet(config, 0);
|
||||
LogConfigOutputSet(config, NULL); /* Will set to stdout */
|
||||
|
@ -106,7 +110,7 @@ LogConfigFree(LogConfig * config)
|
|||
}
|
||||
|
||||
fclose(config->out);
|
||||
free(config);
|
||||
Free(config);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
12
src/Queue.c
12
src/Queue.c
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
#include <Queue.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <Memory.h>
|
||||
|
||||
struct Queue
|
||||
{
|
||||
|
@ -44,16 +44,16 @@ QueueCreate(size_t size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
q = malloc(sizeof(Queue));
|
||||
q = Malloc(sizeof(Queue));
|
||||
if (!q)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
q->items = malloc(size * sizeof(void *));
|
||||
q->items = Malloc(size * sizeof(void *));
|
||||
if (!q->items)
|
||||
{
|
||||
free(q);
|
||||
Free(q);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -69,10 +69,10 @@ QueueFree(Queue * q)
|
|||
{
|
||||
if (q)
|
||||
{
|
||||
free(q->items);
|
||||
Free(q->items);
|
||||
}
|
||||
|
||||
free(q);
|
||||
Free(q);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#include <Routes.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Memory.h>
|
||||
#include <Json.h>
|
||||
#include <HashMap.h>
|
||||
|
||||
|
@ -38,19 +38,19 @@ ROUTE(RouteMatrix)
|
|||
|
||||
if (!MATRIX_PATH_EQUALS(pathPart, "client") || MATRIX_PATH_PARTS(path) != 1)
|
||||
{
|
||||
free(pathPart);
|
||||
Free(pathPart);
|
||||
HttpResponseStatus(context, HTTP_NOT_FOUND);
|
||||
return MatrixErrorCreate(M_NOT_FOUND);
|
||||
}
|
||||
|
||||
free(pathPart);
|
||||
Free(pathPart);
|
||||
pathPart = MATRIX_PATH_POP(path);
|
||||
|
||||
if (MATRIX_PATH_EQUALS(pathPart, "versions"))
|
||||
{
|
||||
Array *versions = ArrayCreate();
|
||||
|
||||
free(pathPart);
|
||||
Free(pathPart);
|
||||
|
||||
ArrayAdd(versions, JsonValueString(UtilStringDuplicate("v1.4")));
|
||||
|
||||
|
@ -61,7 +61,7 @@ ROUTE(RouteMatrix)
|
|||
}
|
||||
else
|
||||
{
|
||||
free(pathPart);
|
||||
Free(pathPart);
|
||||
HttpResponseStatus(context, HTTP_NOT_FOUND);
|
||||
return MatrixErrorCreate(M_NOT_FOUND);
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#include <Routes.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Memory.h>
|
||||
#include <Json.h>
|
||||
#include <HashMap.h>
|
||||
|
||||
|
@ -36,19 +36,19 @@ ROUTE(RouteWellKnown)
|
|||
|
||||
if (!MATRIX_PATH_EQUALS(pathPart, "matrix") || MATRIX_PATH_PARTS(path) != 1)
|
||||
{
|
||||
free(pathPart);
|
||||
Free(pathPart);
|
||||
HttpResponseStatus(context, HTTP_NOT_FOUND);
|
||||
return MatrixErrorCreate(M_NOT_FOUND);
|
||||
}
|
||||
|
||||
free(pathPart);
|
||||
Free(pathPart);
|
||||
pathPart = MATRIX_PATH_POP(path);
|
||||
|
||||
if (MATRIX_PATH_EQUALS(pathPart, "client"))
|
||||
{
|
||||
HashMap *homeserver = HashMapCreate();
|
||||
|
||||
free(pathPart);
|
||||
Free(pathPart);
|
||||
|
||||
response = HashMapCreate();
|
||||
|
||||
|
@ -67,7 +67,7 @@ ROUTE(RouteWellKnown)
|
|||
}
|
||||
else
|
||||
{
|
||||
free(pathPart);
|
||||
Free(pathPart);
|
||||
HttpResponseStatus(context, HTTP_NOT_FOUND);
|
||||
return MatrixErrorCreate(M_NOT_FOUND);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
#include <TelodendriaConfig.h>
|
||||
#include <Memory.h>
|
||||
#include <Config.h>
|
||||
#include <HashMap.h>
|
||||
#include <Log.h>
|
||||
|
@ -83,12 +84,14 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
tConfig = calloc(1, sizeof(TelodendriaConfig));
|
||||
tConfig = Malloc(sizeof(TelodendriaConfig));
|
||||
if (!tConfig)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(tConfig, 0, sizeof(TelodendriaConfig));
|
||||
|
||||
directive = (ConfigDirective *) HashMapGet(config, "listen");
|
||||
children = ConfigChildrenGet(directive);
|
||||
value = ConfigValuesGet(directive);
|
||||
|
@ -129,7 +132,7 @@ TelodendriaConfigParse(HashMap * config, LogConfig * lc)
|
|||
else
|
||||
{
|
||||
Log(lc, LOG_WARNING, "Base URL not specified. Assuming it's 'https://%s'.", tConfig->serverName);
|
||||
tConfig->baseUrl = malloc(strlen(tConfig->serverName) + 10);
|
||||
tConfig->baseUrl = Malloc(strlen(tConfig->serverName) + 10);
|
||||
if (!tConfig->baseUrl)
|
||||
{
|
||||
Log(lc, LOG_ERROR, "Error allocating memory for default config value 'base-url'.");
|
||||
|
@ -391,13 +394,13 @@ TelodendriaConfigFree(TelodendriaConfig * tConfig)
|
|||
return;
|
||||
}
|
||||
|
||||
free(tConfig->serverName);
|
||||
free(tConfig->baseUrl);
|
||||
free(tConfig->identityServer);
|
||||
Free(tConfig->serverName);
|
||||
Free(tConfig->baseUrl);
|
||||
Free(tConfig->identityServer);
|
||||
|
||||
free(tConfig->uid);
|
||||
free(tConfig->gid);
|
||||
free(tConfig->dataDir);
|
||||
Free(tConfig->uid);
|
||||
Free(tConfig->gid);
|
||||
Free(tConfig->dataDir);
|
||||
|
||||
free(tConfig);
|
||||
Free(tConfig);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
*/
|
||||
#include <Util.h>
|
||||
|
||||
#include <Memory.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
@ -45,7 +47,7 @@ UtilUtf8Encode(unsigned long utf8)
|
|||
{
|
||||
char *str;
|
||||
|
||||
str = malloc(5 * sizeof(char));
|
||||
str = Malloc(5 * sizeof(char));
|
||||
if (!str)
|
||||
{
|
||||
return NULL;
|
||||
|
@ -96,7 +98,7 @@ UtilStringDuplicate(char *inStr)
|
|||
char *outStr;
|
||||
|
||||
len = strlen(inStr);
|
||||
outStr = malloc(len + 1); /* For the null terminator */
|
||||
outStr = Malloc(len + 1); /* For the null terminator */
|
||||
if (!outStr)
|
||||
{
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in a new issue