1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

removed NULL-checks after malloc: they are not necessary, they were not consequently used and objects constructed by 3rd party libs are also unchecked

This commit is contained in:
Falk Werner 2020-03-21 21:22:22 +01:00
parent 220df4ad50
commit 214d6b738d
22 changed files with 101 additions and 168 deletions

View File

@ -11,13 +11,10 @@ struct wf_impl_authenticator * wf_impl_authenticator_create(
void * user_data) void * user_data)
{ {
struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator)); struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator));
if (NULL != authenticator)
{
authenticator->type = strdup(type); authenticator->type = strdup(type);
authenticator->authenticate = authenticate; authenticator->authenticate = authenticate;
authenticator->user_data = user_data; authenticator->user_data = user_data;
authenticator->next = NULL; authenticator->next = NULL;
}
return authenticator; return authenticator;
} }

View File

@ -99,15 +99,12 @@ struct wf_impl_filesystem * wf_impl_filesystem_create(
struct wf_mountpoint * mountpoint) struct wf_mountpoint * mountpoint)
{ {
struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem)); struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem));
if (NULL != filesystem)
{
bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint); bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint);
if (!success) if (!success)
{ {
free(filesystem); free(filesystem);
filesystem = NULL; filesystem = NULL;
} }
}
return filesystem; return filesystem;
} }

View File

@ -20,7 +20,7 @@ static char * wf_impl_fill_buffer(
*status = WF_GOOD; *status = WF_GOOD;
char * buffer = malloc(count); char * buffer = malloc(count);
if ((NULL != buffer) && (0 < count)) if (0 < count)
{ {
if (0 == strcmp("identity", format)) if (0 == strcmp("identity", format))
{ {

View File

@ -83,14 +83,11 @@ struct wf_server * wf_impl_server_create(
if (wf_impl_mountpoint_factory_isvalid(&config->mountpoint_factory)) if (wf_impl_mountpoint_factory_isvalid(&config->mountpoint_factory))
{ {
server = malloc(sizeof(struct wf_server)); server = malloc(sizeof(struct wf_server));
if (NULL != server)
{
wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory); wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory);
wf_impl_server_config_clone(config, &server->config); wf_impl_server_config_clone(config, &server->config);
wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators); wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
server->context = wf_impl_server_context_create(server); server->context = wf_impl_server_context_create(server);
} }
}
return server; return server;
} }

View File

@ -56,10 +56,7 @@ void wf_impl_server_config_clone(
struct wf_server_config * wf_impl_server_config_create(void) struct wf_server_config * wf_impl_server_config_create(void)
{ {
struct wf_server_config * config = malloc(sizeof(struct wf_server_config)); struct wf_server_config * config = malloc(sizeof(struct wf_server_config));
if (NULL != config)
{
wf_impl_server_config_init(config); wf_impl_server_config_init(config);
}
return config; return config;
} }

View File

@ -85,14 +85,11 @@ struct wf_server_protocol * wf_impl_server_protocol_create(
void * create_mountpoint_context) void * create_mountpoint_context)
{ {
struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol)); struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol));
if (NULL != protocol)
{
struct wf_impl_mountpoint_factory mountpoint_factory; struct wf_impl_mountpoint_factory mountpoint_factory;
wf_impl_mountpoint_factory_init(&mountpoint_factory, wf_impl_mountpoint_factory_init(&mountpoint_factory,
create_mountpoint, create_mountpoint_context); create_mountpoint, create_mountpoint_context);
wf_impl_server_protocol_init(protocol, &mountpoint_factory); wf_impl_server_protocol_init(protocol, &mountpoint_factory);
}
return protocol; return protocol;

View File

@ -51,8 +51,6 @@ struct wf_impl_session * wf_impl_session_create(
{ {
struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session)); struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session));
if (NULL != session)
{
wf_slist_init(&session->filesystems); wf_slist_init(&session->filesystems);
session->wsi = wsi; session->wsi = wsi;
@ -62,7 +60,6 @@ struct wf_impl_session * wf_impl_session_create(
session->mountpoint_factory = mountpoint_factory; session->mountpoint_factory = mountpoint_factory;
session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
wf_slist_init(&session->messages); wf_slist_init(&session->messages);
}
return session; return session;
} }

View File

@ -12,14 +12,11 @@ extern struct wf_message * wf_message_create(json_t const * value)
{ {
char * data = malloc(sizeof(struct wf_message) + LWS_PRE + length); char * data = malloc(sizeof(struct wf_message) + LWS_PRE + length);
message = (struct wf_message *) data; message = (struct wf_message *) data;
if (NULL != message)
{
message->data = &data[sizeof(struct wf_message) + LWS_PRE]; message->data = &data[sizeof(struct wf_message) + LWS_PRE];
message->length = length; message->length = length;
json_dumpb(value, message->data, length, JSON_COMPACT); json_dumpb(value, message->data, length, JSON_COMPACT);
} }
}
return message; return message;
} }

View File

@ -16,8 +16,6 @@ char * wf_create_string(char const * format, ...)
if (0 <= needed) if (0 <= needed)
{ {
result = malloc(needed + 1); result = malloc(needed + 1);
if (NULL != result)
{
va_list args; va_list args;
va_start(args, format); va_start(args, format);
int count = vsnprintf(result, needed + 1, format, args); int count = vsnprintf(result, needed + 1, format, args);
@ -29,7 +27,6 @@ char * wf_create_string(char const * format, ...)
result = NULL; result = NULL;
} }
} }
}
return result; return result;
} }

View File

@ -30,8 +30,6 @@ struct wfp_client * wfp_impl_client_create(
wf_lwslog_disable(); wf_lwslog_disable();
struct wfp_client * client = malloc(sizeof(struct wfp_client)); struct wfp_client * client = malloc(sizeof(struct wfp_client));
if (NULL != client)
{
wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data); wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data);
memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT); memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT);
@ -49,7 +47,6 @@ struct wfp_client * wfp_impl_client_create(
} }
client->context = lws_create_context(&client->info); client->context = lws_create_context(&client->info);
}
return client; return client;
} }

View File

@ -6,13 +6,10 @@
struct wfp_client_config * wfp_impl_client_config_create(void) struct wfp_client_config * wfp_impl_client_config_create(void)
{ {
struct wfp_client_config * config = malloc(sizeof(struct wfp_client_config)); struct wfp_client_config * config = malloc(sizeof(struct wfp_client_config));
if (NULL != config)
{
wfp_impl_provider_init(&config->provider); wfp_impl_provider_init(&config->provider);
config->user_data = NULL; config->user_data = NULL;
config->key_path = NULL; config->key_path = NULL;
config->cert_path = NULL; config->cert_path = NULL;
}
return config; return config;
} }

View File

@ -270,10 +270,7 @@ struct wfp_client_protocol * wfp_impl_client_protocol_create(
struct wfp_client_config const * config) struct wfp_client_config const * config)
{ {
struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol)); struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol));
if (NULL != protocol)
{
wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data); wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data);
}
return protocol; return protocol;
} }

View File

@ -4,10 +4,7 @@
struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void) struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void)
{ {
struct wfp_dirbuffer * buffer = malloc(sizeof(struct wfp_dirbuffer)); struct wfp_dirbuffer * buffer = malloc(sizeof(struct wfp_dirbuffer));
if (NULL != buffer)
{
buffer->entries = json_array(); buffer->entries = json_array();
}
return buffer; return buffer;
} }

View File

@ -56,8 +56,6 @@ void wfp_impl_respond_read(
{ {
size_t const size = wf_base64_encoded_size(length) + 1; size_t const size = wf_base64_encoded_size(length) + 1;
char * buffer = malloc(size); char * buffer = malloc(size);
if (NULL != buffer)
{
wf_base64_encode((uint8_t const *) data, length, buffer, size); wf_base64_encode((uint8_t const *) data, length, buffer, size);
json_t * result = json_object(); json_t * result = json_object();
@ -69,11 +67,6 @@ void wfp_impl_respond_read(
free(buffer); free(buffer);
} }
else else
{
wfp_impl_respond_error(request, WF_BAD);
}
}
else
{ {
json_t * result = json_object(); json_t * result = json_object();
json_object_set_new(result, "data", json_string("")); json_object_set_new(result, "data", json_string(""));

View File

@ -8,12 +8,9 @@ struct wfp_request * wfp_impl_request_create(
int id) int id)
{ {
struct wfp_request * request = malloc(sizeof(struct wfp_request)); struct wfp_request * request = malloc(sizeof(struct wfp_request));
if (NULL != request)
{
request->respond = prototype->respond; request->respond = prototype->respond;
request->user_data = prototype->user_data; request->user_data = prototype->user_data;
request->id = id; request->id = id;
}
return request; return request;
} }

View File

@ -8,13 +8,10 @@ struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create(
void * user_data) void * user_data)
{ {
struct wf_jsonrpc_method * method = malloc(sizeof(struct wf_jsonrpc_method)); struct wf_jsonrpc_method * method = malloc(sizeof(struct wf_jsonrpc_method));
if (NULL != method)
{
method->next = NULL; method->next = NULL;
method->name = strdup(method_name); method->name = strdup(method_name);
method->invoke = invoke; method->invoke = invoke;
method->user_data = user_data; method->user_data = user_data;
}
return method; return method;
} }

View File

@ -16,10 +16,7 @@ wf_jsonrpc_impl_proxy_create(
void * user_data) void * user_data)
{ {
struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy)); struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy));
if (NULL != proxy)
{
wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data);
}
return proxy; return proxy;
} }

View File

@ -29,12 +29,9 @@ wf_jsonrpc_impl_request_create(
void * user_data) void * user_data)
{ {
struct wf_jsonrpc_request * request = malloc(sizeof(struct wf_jsonrpc_request)); struct wf_jsonrpc_request * request = malloc(sizeof(struct wf_jsonrpc_request));
if (NULL != request)
{
request->id = id; request->id = id;
request->send = send; request->send = send;
request->user_data = user_data; request->user_data = user_data;
}
return request; return request;
} }

View File

@ -24,10 +24,7 @@ struct wf_jsonrpc_server *
wf_jsonrpc_impl_server_create(void) wf_jsonrpc_impl_server_create(void)
{ {
struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server)); struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server));
if (NULL != server)
{
wf_jsonrpc_impl_server_init(server); wf_jsonrpc_impl_server_init(server);
}
return server; return server;
} }

View File

@ -14,10 +14,7 @@ struct wf_timer_manager *
wf_timer_impl_manager_create(void) wf_timer_impl_manager_create(void)
{ {
struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager)); struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager));
if (NULL != manager)
{
manager->timers = NULL; manager->timers = NULL;
}
return manager; return manager;
} }

View File

@ -45,8 +45,6 @@ wf_path_create(
char const * value) char const * value)
{ {
struct wf_path * path = malloc(sizeof(struct wf_path)); struct wf_path * path = malloc(sizeof(struct wf_path));
if (NULL != path)
{
path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY); path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY);
path->capacity = WF_PATH_DEFAULT_CAPACITY; path->capacity = WF_PATH_DEFAULT_CAPACITY;
path->count = 0; path->count = 0;
@ -61,7 +59,6 @@ wf_path_create(
} }
wf_path_add(path, remainder, strlen(remainder)); wf_path_add(path, remainder, strlen(remainder));
}
return path; return path;
} }

View File

@ -332,8 +332,6 @@ wfp_static_filesystem_create(
(void) config; (void) config;
struct wfp_static_filesystem * filesystem = malloc(sizeof(struct wfp_static_filesystem)); struct wfp_static_filesystem * filesystem = malloc(sizeof(struct wfp_static_filesystem));
if (NULL != filesystem)
{
filesystem->entries = malloc(sizeof(struct wfp_static_filesystem_entry) * WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY); filesystem->entries = malloc(sizeof(struct wfp_static_filesystem_entry) * WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY);
filesystem->size = 0; filesystem->size = 0;
filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY; filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY;
@ -346,7 +344,6 @@ wfp_static_filesystem_create(
wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir); wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir);
wfp_client_config_set_onopen(config, &wfp_static_filesystem_open); wfp_client_config_set_onopen(config, &wfp_static_filesystem_open);
wfp_client_config_set_onread(config, &wfp_static_filesystem_read); wfp_client_config_set_onread(config, &wfp_static_filesystem_read);
}
return filesystem; return filesystem;
} }