[xiph-commits] r9143 - icecast/branches/kh/icecast/src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Fri Apr 15 14:22:24 PDT 2005


Author: karl
Date: 2005-04-15 14:22:21 -0700 (Fri, 15 Apr 2005)
New Revision: 9143

Modified:
   icecast/branches/kh/icecast/src/fserve.c
Log:
remove leftover code, plugged a couple of leaks when using fserve


Modified: icecast/branches/kh/icecast/src/fserve.c
===================================================================
--- icecast/branches/kh/icecast/src/fserve.c	2005-04-15 19:33:17 UTC (rev 9142)
+++ icecast/branches/kh/icecast/src/fserve.c	2005-04-15 21:22:21 UTC (rev 9143)
@@ -317,15 +317,20 @@
 const char *fserve_content_type (const char *path)
 {
     const char *ext = util_get_extension(path);
-    mime_type exttype = {strdup(ext), NULL};
+    mime_type exttype = { NULL, NULL };
     void *result;
 
+    if (ext == NULL)
+        return "text/html";
+    exttype.ext = strdup (ext);
     if (!avl_get_by_key (mimetypes, &exttype, &result))
     {
         mime_type *mime = result;
+        free (exttype.ext);
         return mime->type;
     }
     else {
+        free (exttype.ext);
         /* Fallbacks for a few basic ones */
         if(!strcmp(ext, "ogg"))
             return "application/ogg";
@@ -337,6 +342,8 @@
             return "text/css";
         else if(!strcmp(ext, "txt"))
             return "text/plain";
+        else if(!strcmp(ext, "m3u"))
+            return "audio/x-mpegurl";
         else
             return "application/octet-stream";
     }
@@ -358,10 +365,8 @@
 
 int fserve_client_create(client_t *httpclient, const char *path)
 {
-    fserve_t *client = calloc(1, sizeof(fserve_t));
+    fserve_t *client;
     int bytes;
-    int client_limit;
-    ice_config_t *config = config_get_config();
     struct stat file_buf;
     char *range = NULL;
     int64_t new_content_len = 0;
@@ -370,10 +375,6 @@
     char *fullpath;
     int m3u_requested = 0, m3u_file_available = 1;
 
-    // server limit check should be done earlier
-    client_limit = config->client_limit;
-    config_release_config();
-
     fullpath = util_get_path_from_normalised_uri (path);
     INFO2 ("handle file %s (%s)", path, fullpath);
 
@@ -405,7 +406,7 @@
         httpclient->respcode = 200;
         if (host == NULL)
         {
-            config = config_get_config();
+            ice_config_t *config = config_get_config();
             host = strdup (config->hostname);
             port = config->port;
             config_release_config();
@@ -449,7 +450,15 @@
         return 0;
     }
 
+    client = calloc (1, sizeof(fserve_t));
+    if (client == NULL)
+    {
+        free (fullpath);
+        client_send_404 (httpclient, "memory exhausted");
+        return 0;
+    }
     client->file = fopen (fullpath, "rb");
+    free (fullpath);
     if (client->file == NULL)
     {
         client_send_404 (httpclient, "File not readable");



More information about the commits mailing list