[FIX] Fix memory issue mentionned in #33.

This commit is contained in:
lda 2023-09-06 07:37:49 +02:00
parent 3ecbef27af
commit c626b2f4f2
1 changed files with 10 additions and 6 deletions

View File

@ -52,6 +52,8 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
char *searchTerm = NULL;
char *requesterName = NULL;
char *error;
size_t limit = 10;
size_t i, included;
@ -62,7 +64,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
if (HttpRequestMethodGet(args->context) != HTTP_POST)
{
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED);
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
goto finish;
}
@ -70,7 +72,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
if (!request)
{
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_NOT_JSON);
response = MatrixErrorCreate(M_NOT_JSON, NULL);
goto finish;
}
@ -85,7 +87,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
if (!user)
{
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
goto finish;
}
requesterName = UserGetName(user);
@ -96,7 +98,8 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
{
/* The Spec requires search_term to be set to a string. */
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON);
error = "search_term is not a string, or is non-existent";
response = MatrixErrorCreate(M_BAD_JSON, error);
goto finish;
}
searchTerm = StrLower(JsonValueAsString(val));
@ -120,9 +123,10 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
config = ConfigLock(db);
if (!config)
{
Log(LOG_ERR, "Directory endpoint failed to lock configuration.");
error = "Directory endpoint failed to lock configuration.";
Log(LOG_ERR, error);
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
response = MatrixErrorCreate(M_UNKNOWN);
response = MatrixErrorCreate(M_UNKNOWN, error);
goto finish;
}