You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2019/07/22 19:48:15 UTC

[celix] branch develop updated: Fixes two strtok_r calls in http_admin and a memleak in etcdlib

This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/develop by this push:
     new f9b906b  Fixes two strtok_r calls in http_admin and a memleak in etcdlib
f9b906b is described below

commit f9b906b01c657c7a6a0ac239c13cd6886d5b8f95
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Mon Jul 22 21:47:25 2019 +0200

    Fixes two strtok_r calls in http_admin and a memleak in etcdlib
---
 bundles/http_admin/http_admin/src/service_tree.c     | 4 ++--
 bundles/http_admin/test/test/http_websocket_tests.cc | 8 ++------
 libs/etcdlib/src/etcd.c                              | 5 ++++-
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/bundles/http_admin/http_admin/src/service_tree.c b/bundles/http_admin/http_admin/src/service_tree.c
index 97590b1..122b50b 100644
--- a/bundles/http_admin/http_admin/src/service_tree.c
+++ b/bundles/http_admin/http_admin/src/service_tree.c
@@ -92,7 +92,7 @@ bool addServiceNode(service_tree_t *svc_tree, const char *uri, void *svc) {
     service_node_data_t *current_data = current->svc_data;
     while (req_uri != NULL) {
         char *tmp_save_ptr = save_ptr;
-        char *next_token = strtok_r(uri_cpy, "/", &tmp_save_ptr);
+        char *next_token = strtok_r(NULL, "/", &tmp_save_ptr);
         bool is_last_entry = next_token == NULL;
         if (strcmp(current_data->sub_uri, req_uri) == 0) {
             if (is_last_entry) {
@@ -113,7 +113,7 @@ bool addServiceNode(service_tree_t *svc_tree, const char *uri, void *svc) {
                 //Parent has no sub URIs registered yet
                 req_uri = strtok_r(NULL, "/", &save_ptr);
                 tmp_save_ptr = save_ptr;
-                next_token = strtok_r(uri_cpy, "/", &tmp_save_ptr);
+                next_token = strtok_r(NULL, "/", &tmp_save_ptr);
                 is_last_entry = next_token == NULL;
                 service_tree_node_t *node = createServiceNode(current, NULL, NULL, NULL,
                                                               req_uri, (is_last_entry ? svc : NULL));
diff --git a/bundles/http_admin/test/test/http_websocket_tests.cc b/bundles/http_admin/test/test/http_websocket_tests.cc
index 216f4c6..409d095 100644
--- a/bundles/http_admin/test/test/http_websocket_tests.cc
+++ b/bundles/http_admin/test/test/http_websocket_tests.cc
@@ -188,16 +188,12 @@ TEST(HTTP_ADMIN_INT_GROUP, http_put_echo_alias_test) {
     response_info = mg_get_response_info(connection);
     CHECK(response_info != nullptr);
     int read_bytes = mg_read(connection, rcv_buf, sizeof(rcv_buf));
-#ifndef __APPLE__
-    //TODO fixme for apple, for now getting a 401 (not authorized back)
-    CHECK_EQUAL(response_info->status_code, 200);
+
+    CHECK_EQUAL(200, response_info->status_code);
 
     //Expect an echo which is the same as the request body
     CHECK(read_bytes == (int) strlen(data_str));
     CHECK(strncmp(rcv_buf, data_str, read_bytes) == 0);
-#else
-    CHECK_EQUAL(0, read_bytes);
-#endif
 
     mg_close_connection(connection);
 }
diff --git a/libs/etcdlib/src/etcd.c b/libs/etcdlib/src/etcd.c
index c6d7627..580da9d 100644
--- a/libs/etcdlib/src/etcd.c
+++ b/libs/etcdlib/src/etcd.c
@@ -110,7 +110,10 @@ etcdlib_t* etcdlib_create(const char* server, int port, int flags) {
 }
 
 void etcdlib_destroy(etcdlib_t *etcdlib) {
-	free(etcdlib);
+    if (etcdlib != NULL) {
+        free(etcdlib->host);
+    }
+    free(etcdlib);
 }
 
 int etcd_get(const char* key, char** value, int* modifiedIndex) {