coap-server.c: fix memory leak in hnd_unkown_put()

Reverse the sequence of sanity checks to avoid allocating a new object
when not necessary.

This fixes CID 1483549.
This commit is contained in:
Olaf Bergmann committed 2020-06-19 16:49:13 +02:00
1 parent c98cc237b3
commit 784c2ddc5f
1 file changed
+7 -8
+7 -8
View File
@@ -647,15 +647,16 @@ hnd_unknown_put(coap_context_t *ctx,
coap_resource_t *r;
coap_string_t *uri_path;
/* get the uri_path - will will get used by coap_resource_init() */
uri_path = coap_get_uri_path(request);
if (!uri_path) {
response->code = COAP_RESPONSE_CODE(404);
/* check if creating a new resource is allowed */
if (dynamic_count >= support_dynamic) {
response->code = COAP_RESPONSE_CODE(406);
return;
}
if (dynamic_count >= support_dynamic) {
response->code = COAP_RESPONSE_CODE(406);
/* get the uri_path - will get used by coap_resource_init() */
uri_path = coap_get_uri_path(request);
if (!uri_path) {
response->code = COAP_RESPONSE_CODE(404);
return;
}
@@ -675,8 +676,6 @@ hnd_unknown_put(coap_context_t *ctx,
/* Do the PUT for this first call */
hnd_put(ctx, r, session, request, token, query, response);
return;
}
static void