]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Various fixes for scan-build warnings 807/head
authorVictor Julien <victor@inliniac.net>
Thu, 30 Jan 2014 14:22:55 +0000 (15:22 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 30 Jan 2014 14:22:55 +0000 (15:22 +0100)
src/output-json-http.c
src/output-json-tls.c
src/output-json.c

index 747d03b8ff8046456b6d6b32d8f513283b71e608..fc5028a66ffd942de7f1878ca96fa368d4f0a28f 100644 (file)
@@ -85,9 +85,10 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
     {
         c = SCStrndup((char *)bstr_ptr(tx->request_hostname),
                       bstr_len(tx->request_hostname));
-        json_object_set_new(hjs, "hostname", json_string(c));
-        if (c != NULL)
+        if (c != NULL) {
+            json_object_set_new(hjs, "hostname", json_string(c));
             SCFree(c);
+        }
     } else {
         json_object_set_new(hjs, "hostname", json_string("<hostname unknown>"));
     }
@@ -97,9 +98,10 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
     {
         c = SCStrndup((char *)bstr_ptr(tx->request_uri),
                       bstr_len(tx->request_uri));
-        json_object_set_new(hjs, "uri", json_string(c));
-        if (c != NULL)
+        if (c != NULL) {
+            json_object_set_new(hjs, "uri", json_string(c));
             SCFree(c);
+        }
     }
 
     /* user agent */
@@ -110,9 +112,10 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
     if (h_user_agent != NULL) {
         c = SCStrndup((char *)bstr_ptr(h_user_agent->value),
                       bstr_len(h_user_agent->value));
-        json_object_set_new(hjs, "user-agent", json_string(c));
-        if (c != NULL)
+        if (c != NULL) {
+            json_object_set_new(hjs, "user-agent", json_string(c));
             SCFree(c);
+        }
     } else {
         json_object_set_new(hjs, "user-agent", json_string("<useragent unknown>"));
     }
@@ -125,9 +128,10 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
     if (h_x_forwarded_for != NULL) {
         c = SCStrndup((char *)bstr_ptr(h_x_forwarded_for->value),
                       bstr_len(h_x_forwarded_for->value));
-        json_object_set_new(hjs, "xff", json_string(c));
-        if (c != NULL)
+        if (c != NULL) {
+            json_object_set_new(hjs, "xff", json_string(c));
             SCFree(c);
+        }
     }
 
     /* content-type */
@@ -139,14 +143,14 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
         char *p;
         c = SCStrndup((char *)bstr_ptr(h_content_type->value),
                       bstr_len(h_content_type->value));
-        p = strchrnul(c, ';');
-        *p = '\0';
-        json_object_set_new(hjs, "content-type", json_string(c));
-        if (c != NULL)
+        if (c != NULL) {
+            p = strchrnul(c, ';');
+            *p = '\0';
+            json_object_set_new(hjs, "content-type", json_string(c));
             SCFree(c);
+        }
     }
 
-#if 1
     if (http_ctx->flags & LOG_HTTP_EXTENDED) {
         /* referer */
         htp_header_t *h_referer = NULL;
@@ -156,51 +160,55 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
         if (h_referer != NULL) {
             c = SCStrndup((char *)bstr_ptr(h_referer->value),
                           bstr_len(h_referer->value));
-            json_object_set_new(hjs, "referer", json_string(c));
-            if (c != NULL)
+            if (c != NULL) {
+                json_object_set_new(hjs, "referer", json_string(c));
                 SCFree(c);
+            }
         }
 
         /* method */
         if (tx->request_method != NULL) {
             c = SCStrndup((char *)bstr_ptr(tx->request_method),
                           bstr_len(tx->request_method));
-            json_object_set_new(hjs, "method", json_string(c));
-            if (c != NULL)
+            if (c != NULL) {
+                json_object_set_new(hjs, "method", json_string(c));
                 SCFree(c);
+            }
         }
 
         /* protocol */
         if (tx->request_protocol != NULL) {
             c = SCStrndup((char *)bstr_ptr(tx->request_protocol),
                           bstr_len(tx->request_protocol));
-            json_object_set_new(hjs, "protocol", json_string(c));
-            if (c != NULL)
+            if (c != NULL) {
+                json_object_set_new(hjs, "protocol", json_string(c));
                 SCFree(c);
+            }
         }
 
         /* response status */
         if (tx->response_status != NULL) {
             c = SCStrndup((char *)bstr_ptr(tx->response_status),
                           bstr_len(tx->response_status));
-            json_object_set_new(hjs, "status", json_string(c));
-            if (c != NULL)
+            if (c != NULL) {
+                json_object_set_new(hjs, "status", json_string(c));
                 SCFree(c);
+            }
 
             htp_header_t *h_location = htp_table_get_c(tx->response_headers, "location");
             if (h_location != NULL) {
                 c = SCStrndup((char *)bstr_ptr(h_location->value),
                               bstr_len(h_location->value));
-                json_object_set_new(hjs, "redirect", json_string(c));
-                if (c != NULL)
+                if (c != NULL) {
+                    json_object_set_new(hjs, "redirect", json_string(c));
                     SCFree(c);
+                }
             }
         }
 
         /* length */
         json_object_set_new(hjs, "length", json_integer(tx->response_message_len));
     }
-#endif
 
     json_object_set_new(js, "http", hjs);
 }
@@ -248,12 +256,17 @@ OutputCtx *OutputHttpLogInit(ConfNode *conf)
     }
 
     LogHttpFileCtx *http_ctx = SCMalloc(sizeof(LogHttpFileCtx));
-    if (unlikely(http_ctx == NULL))
+    if (unlikely(http_ctx == NULL)) {
+        LogFileFreeCtx(file_ctx);
         return NULL;
+    }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
-    if (unlikely(output_ctx == NULL))
+    if (unlikely(output_ctx == NULL)) {
+        LogFileFreeCtx(file_ctx);
+        SCFree(http_ctx);
         return NULL;
+    }
 
     http_ctx->file_ctx = file_ctx;
     http_ctx->flags = LOG_HTTP_DEFAULT;
@@ -282,8 +295,10 @@ OutputCtx *OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
         return NULL;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
-    if (unlikely(output_ctx == NULL))
+    if (unlikely(output_ctx == NULL)) {
+        SCFree(http_ctx);
         return NULL;
+    }
 
     http_ctx->file_ctx = ajt->file_ctx;
     http_ctx->flags = LOG_HTTP_DEFAULT;
index 4b859fda407ad8bb23143de5397e7a3694f8aadd..fa23129994fc831ab6733e9df63b0545cf9bcfa3 100644 (file)
@@ -234,12 +234,17 @@ OutputCtx *OutputTlsLogInit(ConfNode *conf)
     }
 
     OutputTlsCtx *tls_ctx = SCMalloc(sizeof(OutputTlsCtx));
-    if (unlikely(tls_ctx == NULL))
+    if (unlikely(tls_ctx == NULL)) {
+        LogFileFreeCtx(file_ctx);
         return NULL;
+    }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
-    if (unlikely(output_ctx == NULL))
+    if (unlikely(output_ctx == NULL)) {
+        LogFileFreeCtx(file_ctx);
+        SCFree(tls_ctx);
         return NULL;
+    }
 
     tls_ctx->file_ctx = file_ctx;
     tls_ctx->flags = LOG_TLS_DEFAULT;
@@ -274,8 +279,10 @@ OutputCtx *OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
         return NULL;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
-    if (unlikely(output_ctx == NULL))
+    if (unlikely(output_ctx == NULL)) {
+        SCFree(tls_ctx);
         return NULL;
+    }
 
     tls_ctx->file_ctx = ajt->file_ctx;
     tls_ctx->flags = LOG_TLS_DEFAULT;
index ac569f134a8cd9bdf0bb4d9f3f40ab1ab1b3b996..c3ba9a97d2db6db31db254cd9ce61d93abc1090c 100644 (file)
@@ -373,8 +373,11 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
-    if (unlikely(output_ctx == NULL))
+    if (unlikely(output_ctx == NULL)) {
+        LogFileFreeCtx(json_ctx->file_ctx);
+        SCFree(json_ctx);
         return NULL;
+    }
 
     output_ctx->data = json_ctx;
     output_ctx->DeInit = OutputJsonDeInitCtx;
@@ -401,6 +404,7 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
 
             if (SCConfLogOpenGeneric(conf, json_ctx->file_ctx, DEFAULT_LOG_FILENAME) < 0) {
                 LogFileFreeCtx(json_ctx->file_ctx);
+                SCFree(json_ctx);
                 return NULL;
             }