{
static char *line = NULL;
static size_t size = 0;
+ int len;
char buf[BUFSIZE];
char *cp;
while (!feof (stream)) {
if ((cp = fgets (buf, sizeof (buf), stream)) == NULL)
+ {
+ free(line);
+ line = NULL;
return NULL;
+ }
if (strlen(line)+strlen(buf)+1 > size) {
if ((cp = (char *)realloc (line, size + BUFSIZE)) == NULL)
return line;
+ cp[size] = '\0';
size += BUFSIZE;
line = cp;
}
strcat (line, buf);
- if (line[strlen(line)-1] == '\n') {
- line[strlen(line)-1] = '\0';
- if (line[strlen(line)-1] == '\r')
- line[strlen(line)-1] = '\0';
+ len = strlen(line);
+ if (len && line[len-1] == '\n') {
+ line[len-1] = '\0';
+ len --;
+ if (len && line[len-1] == '\r')
+ line[len-1] = '\0';
cgiDebugOutput (4, "Read line '%s'", line);
return line;
}
}
+ free(line);
+ line = NULL;
+
return NULL;
}
memset(pivot, 0, (cp-name + vp-value + 5) * sizeof (char));
strncpy (pivot, name, cp-name);
+ pivot[cp-name] = '\0';
strncat (pivot, ": ", 2);
strncat (pivot, value, vp-value);
strncat (pivot, "\r\n", 2);
void cgiHeader ()
{
if (cgiType)
+ {
printf ("Content-type: %s\r\n", cgiType);
+ free(cgiType);
+ cgiType = NULL;
+ }
else
printf ("Content-type: text/html\r\n");
if (cgiHeaderString)
+ {
printf ("%s", cgiHeaderString);
+ free(cgiHeaderString);
+ cgiHeaderString = NULL;
+ }
printf ("\r\n");
}