]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
htsp server: fix memory leak in htsmsg_binary_deserialize() - free(buf)
authorJaroslav Kysela <perex@perex.cz>
Mon, 20 Jun 2016 08:12:02 +0000 (10:12 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 20 Jun 2016 08:12:02 +0000 (10:12 +0200)
src/htsmsg_binary.c
src/htsp_server.c

index ef5cbf65002f528cdd74f45c22c5bacd762a002a..1755f2dd26844a61d838182185a11a945f7ce0aa 100644 (file)
@@ -147,6 +147,7 @@ htsmsg_binary_deserialize(void *data, size_t len, const void *buf)
   htsmsg_t *msg = htsmsg_create_map();
   int r = htsmsg_binary_des0(msg, data, len);
   if (r < 0) {
+    free(buf);
     htsmsg_destroy(msg);
     return NULL;
   }
@@ -156,6 +157,8 @@ htsmsg_binary_deserialize(void *data, size_t len, const void *buf)
 #if ENABLE_SLOW_MEMORYINFO
     memoryinfo_append(&htsmsg_memoryinfo, len);
 #endif
+  } else {
+    free(buf);
   }
   return msg;
 }
index b511a8eb36f528b2174c365bcb4554e44e4b0251..8b3e4eaabd84eae71b56c16bf5ec1a090d60e8aa 100644 (file)
@@ -2983,7 +2983,7 @@ htsp_read_message(htsp_connection_t *htsp, htsmsg_t **mp, int timeout)
   void *buf;
 
   v = timeout ? tcp_read_timeout(htsp->htsp_fd, data, 4, timeout) : 
-    tcp_read(htsp->htsp_fd, data, 4);
+                tcp_read(htsp->htsp_fd, data, 4);
 
   if(v != 0)
     return v;
@@ -2995,17 +2995,15 @@ htsp_read_message(htsp_connection_t *htsp, htsmsg_t **mp, int timeout)
     return ENOMEM;
 
   v = timeout ? tcp_read_timeout(htsp->htsp_fd, buf, len, timeout) : 
-    tcp_read(htsp->htsp_fd, buf, len);
+                tcp_read(htsp->htsp_fd, buf, len);
   
   if(v != 0) {
     free(buf);
     return v;
   }
 
-  /* buf will be tied to the message.
-   * NB: If the message can not be deserialized buf will be free'd by the
-   * function.
-   */
+  /* buf will be tied to the message (on success) */
+  /* bellow fcn calls free(buf) (on failure) */
   *mp = htsmsg_binary_deserialize(buf, len, buf);
   if(*mp == NULL)
     return EBADMSG;