Re: int urldecode(char *src, char *last, char *dest)



On Feb 16, 7:18 am, "gert" <gert.cuyk...@xxxxxxxxx> wrote:
#include <fcgi_stdio.h>
#include <stdlib.h>

char *post(void){
char *input;
char *lenstr;
long len;
lenstr=getenv("CONTENT_LENGTH");
if (lenstr != NULL && sscanf(lenstr,"%ld",&len)==1 ) {
input = malloc(len+1);
fgets(input, len+1, stdin);
//urldecode(); IMPLEMENT LATER NEED SLEEP FIRST
printf("Content-Type: text/xml; charset=utf-8"
"\r\n"
"\r\n"
"<xml>%s %d</xml>"
"\n"
,input,len);
free(input);
}
return 0;

}

int main (void){
char * input;
while (FCGI_Accept() >= 0) {
post();
}
return 0;

}

Is this Wolf approved, meaning safety code with no memory leaks or
other memory violations ?

Not quite; you use %d to print a long, and you don't
check the result of malloc() for failure.

I can't comment on the non-standard things (ie. whether
or not the output is actually valid, and the behaviour
of the getenv() function), so I'll assume you know what
you're doing there.

.



Relevant Pages

  • Re: [QUESTION]
    ... what creates memory leaks. ... Since the original code has been snipped, ... char *do_it{ ... Assuming that you have a prototype for strdup() in place, and that it's the BSD function I believe you are probably using, then there's nothing wrong with the return statement. ...
    (comp.lang.c)
  • Re: int urldecode(char *src, char *last, char *dest)
    ... As well as causing a buffer overflow if the text ... char *post{ ... meaning safety code with no memory leaks or ...
    (comp.lang.c)
  • Re: Memory leaks help with char*
    ... I'm sure I've got some memory leaks here. ... I get an error when I try to delete my char* variables. ... pszFileName = strcat; ... //delete pfile; ...
    (microsoft.public.vc.language)
  • Re: a curious questions about return type
    ... Andrew Poelstra wrote: ... char month; ... in order to prevent memory leaks. ...
    (comp.lang.c)
  • Re: Curses???
    ... Do I use ioctl() to set the c_lflag. ... have it open (STDIN) and the following code may be more useful to work ... int inhibitStdinInBuffering(void) ... ioctl(STDIN, TCGETA, (char *)&originalIoSettings); ...
    (comp.os.lynx)