Просмотр исходного кода

corrected error handling in post processing example

Sebastian Gerhardt 17 лет назад
Родитель
Сommit
45c6900e36
2 измененных файлов с 9 добавлено и 4 удалено
  1. 5 2
      doc/examples/simplepost.c
  2. 4 2
      doc/processingpost.inc

+ 5 - 2
doc/examples/simplepost.c

@@ -86,7 +86,8 @@ void request_completed (void *cls, struct MHD_Connection *connection, void **con
       if (con_info->answerstring) free (con_info->answerstring);
     }
   
-  free (con_info);      
+  free (con_info);
+  *con_cls = NULL;          
 }
 
 
@@ -100,6 +101,7 @@ int answer_to_connection (void *cls, struct MHD_Connection *connection, const ch
 
       con_info = malloc (sizeof (struct connection_info_struct));
       if (NULL == con_info) return MHD_NO;
+      con_info->answerstring = NULL;
 
       if (0 == strcmp (method, "POST")) 
         {      
@@ -137,7 +139,8 @@ int answer_to_connection (void *cls, struct MHD_Connection *connection, const ch
           
           return MHD_YES;
         } 
-        else return send_page (connection, con_info->answerstring);
+      else
+        if (NULL != con_info->answerstring) return send_page (connection, con_info->answerstring);
     } 
 
   return send_page(connection, errorpage); 

+ 4 - 2
doc/processingpost.inc

@@ -122,7 +122,8 @@ void request_completed (void *cls, struct MHD_Connection *connection, void **con
       if (con_info->answerstring) free (con_info->answerstring);
     }
   
-  free (con_info);      
+  free (con_info);
+  *con_cls = NULL;   
 }
 @end verbatim
 @noindent
@@ -157,6 +158,7 @@ int answer_to_connection (void *cls, struct MHD_Connection *connection, const ch
 
       con_info = malloc (sizeof (struct connection_info_struct));
       if (NULL == con_info) return MHD_NO;
+      con_info->answerstring = NULL;
 @end verbatim
 @noindent
 
@@ -214,7 +216,7 @@ considered---all of it.
           
           return MHD_YES;
         } 
-        else return send_page (connection, con_info->answerstring);
+      else if (NULL != con_info->answerstring) return send_page (connection, con_info->answerstring);
     } 
 @end verbatim
 @noindent