vlc | branch: master | Rafaël Carré <fun...@videolan.org> | Thu Feb 20 18:34:56 2014 +0100| [85724e8f7c66a00154fadf99c737f3722110bae6] | committer: Rafaël Carré
httpd: simplify MsgAdd > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=85724e8f7c66a00154fadf99c737f3722110bae6 --- src/network/httpd.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/network/httpd.c b/src/network/httpd.c index 969b558..0ff81c0 100644 --- a/src/network/httpd.c +++ b/src/network/httpd.c @@ -1297,36 +1297,30 @@ const char *httpd_MsgGet( const httpd_message_t *msg, const char *name ) void httpd_MsgAdd( httpd_message_t *msg, const char *name, const char *psz_value, ... ) { - va_list args; - char *value = NULL; + httpd_header *p_tmp = realloc( msg->p_headers, sizeof(httpd_header) * (msg->i_headers + 1)); + if (!p_tmp) + return; - va_start( args, psz_value ); - if( us_vasprintf( &value, psz_value, args ) == -1 ) - value = NULL; - va_end( args ); + msg->p_headers = p_tmp; - if( value == NULL ) + httpd_header *h = &msg->p_headers[msg->i_headers]; + h->name = strdup(name); + if (!h->name) return; - name = strdup( name ); - if( name == NULL ) - { - free( value ); + h->value = NULL; + + va_list args; + va_start( args, psz_value ); + int ret = us_vasprintf(&h->value, psz_value, args); + va_end( args ); + + if (ret == -1 ) { + free(h->name); return; } - httpd_header * p_tmp = realloc( msg->p_headers, sizeof(httpd_header) * (msg->i_headers + 1)); - if(p_tmp) - { - msg->p_headers = p_tmp; - msg->p_headers[msg->i_headers].name = name; - msg->p_headers[msg->i_headers].value = value; - msg->i_headers++; - } - else - { - free(name); - free(value); - } + + msg->i_headers++; } static void httpd_ClientInit( httpd_client_t *cl, mtime_t now ) _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits