Explorar o código

add check NULL condition

TurtleRuss %!s(int64=2) %!d(string=hai) anos
pai
achega
824eda19e5
Modificáronse 2 ficheiros con 16 adicións e 4 borrados
  1. 8 2
      tftp/tftp_client.c
  2. 8 2
      tftp/tftp_xfer.c

+ 8 - 2
tftp/tftp_client.c

@@ -84,10 +84,16 @@ struct tftp_client *tftp_client_create(const char *ip_addr, int port)
 void tftp_client_destroy(struct tftp_client *client)
 {
     struct tftp_client_private *_private;
-
+    if (client == NULL)
+    {
+        return;
+    }
     _private = client->_private;
     /* Release connection objects */
-    tftp_xfer_destroy(_private->xfer);
+    if (_private && _private->xfer)
+    {
+        tftp_xfer_destroy(_private->xfer);
+    }
     /* Free memory */
     free(client);
 }

+ 8 - 2
tftp/tftp_xfer.c

@@ -369,11 +369,17 @@ struct tftp_xfer *tftp_xfer_create(const char *ip_addr, int port)
 void tftp_xfer_destroy(struct tftp_xfer *xfer)
 {
     struct tftp_xfer_private *_private;
-
+    if (xfer == NULL)
+    {
+        return;
+    }
     /* free all mem */
     _private = xfer->_private;
     closesocket(xfer->sock);
-    free(_private->ip_addr);
+    if (_private && _private->ip_addr)
+    {
+        free(_private->ip_addr);
+    }
     free(xfer->mode);
     free(xfer);
 }