[hamradio-commits] [dump1090] 332/389: B"H net_io.c http server: hopefully mem code is OK now

Matthew Ernisse mernisse-guest at moszumanska.debian.org
Wed Nov 5 00:20:11 UTC 2014


This is an automated email from the git hooks/post-receive script.

mernisse-guest pushed a commit to branch master
in repository dump1090.

commit c265ea1d553c0fb09e22b72ed51058dfea9df35c
Author: hhm <heehooman+vcs-ci at gmail.com>
Date:   Wed Sep 17 07:58:19 2014 -0400

    B"H net_io.c http server: hopefully mem code is OK now
    
    Still learning the ropes memory-wise :-)
---
 net_io.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/net_io.c b/net_io.c
index 4a19429..d1bbd39 100644
--- a/net_io.c
+++ b/net_io.c
@@ -749,15 +749,13 @@ int handleHTTPRequest(struct client *c, char *p) {
         hrp = realpath(HTMLPATH, NULL);
         hrp = (hrp ? hrp : HTMLPATH);
         clen = -1;
-        content = calloc(1, 1);
+        content = strdup("Server error occured");
         if (rp && (!strncmp(hrp, rp, strlen(hrp)))) {
             if (stat(getFile, &sbuf) != -1 && (fd = open(getFile, O_RDONLY)) != -1) {
-                content = (char *) malloc(sbuf.st_size);
+                content = (char *) realloc(content, sbuf.st_size);
                 if (read(fd, content, sbuf.st_size) != -1) {
                     clen = sbuf.st_size;
                     statuscode = 200;
-				} else {
-					free(content);
                 }
             }
         } else {
@@ -766,9 +764,9 @@ int handleHTTPRequest(struct client *c, char *p) {
 
         if (clen < 0) {
             char buf[128];
-            clen = snprintf(buf,sizeof(buf),"Error opening HTML file: %s", strerror(errno));
+            content = realloc(content, sizeof(buf));
+            clen = snprintf(content,sizeof(buf),"Error opening HTML file: %s", strerror(errno));
             statuscode = 404;
-            content = strdup(buf);
         }
         
         if (fd != -1) {
@@ -800,7 +798,7 @@ int handleHTTPRequest(struct client *c, char *p) {
         "Cache-Control: no-cache, must-revalidate\r\n"
         "Expires: Sat, 26 Jul 1997 05:00:00 GMT\r\n"
         "\r\n",
-		statuscode,
+        statuscode,
         ctype,
         keepalive ? "keep-alive" : "close",
         clen);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/dump1090.git



More information about the pkg-hamradio-commits mailing list