소스 검색

response: added PANIC for wrong use

Evgeny Grin (Karlson2k) 1 년 전
부모
커밋
152414c667
2개의 변경된 파일19개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      src/mhd2/mhd_response.h
  2. 13 0
      src/mhd2/response_destroy.c

+ 6 - 1
src/mhd2/mhd_response.h

@@ -354,7 +354,12 @@ struct MHD_Response
    */
   struct mhd_ResponseInternalErrData special_resp;
 
-  #ifndef NDEBUG
+  /**
+   * Should be always 'false' for the response lifetime
+   */
+  bool was_destroyed;
+
+#ifndef NDEBUG
   struct mhd_ResponseDebug dbg;
 #endif
 };

+ 13 - 0
src/mhd2/response_destroy.c

@@ -29,6 +29,7 @@
 #include "mhd_response.h"
 
 #include "mhd_assert.h"
+#include "mhd_panic.h"
 #include "mhd_atomic_counter.h"
 
 #include "sys_malloc.h"
@@ -39,6 +40,9 @@
 #include "response_funcs.h"
 #include "response_from.h"
 
+#define mhd_RESPONSE_DESTOYED "Attempt to use destroyed response, " \
+        "re-use non-reusable response or wrong MHD_Response pointer"
+
 /**
  * Perform full response de-initialisation, with cleaning-up / freeing
  * all content data and headers.
@@ -54,6 +58,8 @@ response_full_deinit (struct MHD_Response *restrict r)
   if (r->reuse.reusable)
     mhd_response_deinit_reusable (r);
   mhd_response_deinit_content_data (r);
+
+  r->was_destroyed = true;
   free (r);
 }
 
@@ -62,6 +68,8 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void
 mhd_response_dec_use_count (struct MHD_Response *restrict r)
 {
   mhd_assert (r->frozen);
+  if (r->was_destroyed)
+    MHD_PANIC (mhd_RESPONSE_DESTOYED);
 
   if (r->reuse.reusable)
   {
@@ -77,6 +85,8 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void
 mhd_response_inc_use_count (struct MHD_Response *restrict r)
 {
   mhd_assert (r->frozen);
+  if (r->was_destroyed)
+    MHD_PANIC (mhd_RESPONSE_DESTOYED);
 
   if (! r->reuse.reusable)
     return;
@@ -89,6 +99,9 @@ MHD_EXTERN_
 MHD_FN_PAR_NONNULL_ (1) void
 MHD_response_destroy (struct MHD_Response *response)
 {
+  if (response->was_destroyed)
+    MHD_PANIC (mhd_RESPONSE_DESTOYED);
+
   if (! response->frozen)
   {
     /* This response has been never used for actions */