comparison stream/http.c @ 32511:b39155e98ac3

Remove some useless NULL pointer checks before invoking free() on the pointer. patch by From: Clment Bsch, ubitux gmail com
author diego
date Sun, 07 Nov 2010 12:47:40 +0000
parents 84299b9bf8aa
children 84bdbf9e9c48
comparison
equal deleted inserted replaced
32510:b756312f1d15 32511:b39155e98ac3
305 305
306 void 306 void
307 http_free( HTTP_header_t *http_hdr ) { 307 http_free( HTTP_header_t *http_hdr ) {
308 HTTP_field_t *field, *field2free; 308 HTTP_field_t *field, *field2free;
309 if( http_hdr==NULL ) return; 309 if( http_hdr==NULL ) return;
310 if( http_hdr->protocol!=NULL ) free( http_hdr->protocol ); 310 free(http_hdr->protocol);
311 if( http_hdr->uri!=NULL ) free( http_hdr->uri ); 311 free(http_hdr->uri);
312 if( http_hdr->reason_phrase!=NULL ) free( http_hdr->reason_phrase ); 312 free(http_hdr->reason_phrase);
313 if( http_hdr->field_search!=NULL ) free( http_hdr->field_search ); 313 free(http_hdr->field_search);
314 if( http_hdr->method!=NULL ) free( http_hdr->method ); 314 free(http_hdr->method);
315 if( http_hdr->buffer!=NULL ) free( http_hdr->buffer ); 315 free(http_hdr->buffer);
316 field = http_hdr->first_field; 316 field = http_hdr->first_field;
317 while( field!=NULL ) { 317 while( field!=NULL ) {
318 field2free = field; 318 field2free = field;
319 if (field->field_name) 319 free(field->field_name);
320 free(field->field_name);
321 field = field->next; 320 field = field->next;
322 free( field2free ); 321 free( field2free );
323 } 322 }
324 free( http_hdr ); 323 free( http_hdr );
325 http_hdr = NULL; 324 http_hdr = NULL;
438 field[len]='\0'; 437 field[len]='\0';
439 http_set_field( http_hdr, field ); 438 http_set_field( http_hdr, field );
440 hdr_ptr = ptr+((*ptr=='\r')?2:1); 439 hdr_ptr = ptr+((*ptr=='\r')?2:1);
441 } while( hdr_ptr<(http_hdr->buffer+pos_hdr_sep) ); 440 } while( hdr_ptr<(http_hdr->buffer+pos_hdr_sep) );
442 441
443 if( field!=NULL ) free( field ); 442 free(field);
444 443
445 if( pos_hdr_sep+hdr_sep_len<http_hdr->buffer_size ) { 444 if( pos_hdr_sep+hdr_sep_len<http_hdr->buffer_size ) {
446 // Response has data! 445 // Response has data!
447 http_hdr->body = http_hdr->buffer+pos_hdr_sep+hdr_sep_len; 446 http_hdr->body = http_hdr->buffer+pos_hdr_sep+hdr_sep_len;
448 http_hdr->body_size = http_hdr->buffer_size-(pos_hdr_sep+hdr_sep_len); 447 http_hdr->body_size = http_hdr->buffer_size-(pos_hdr_sep+hdr_sep_len);
511 // Add the body 510 // Add the body
512 if( http_hdr->body!=NULL ) { 511 if( http_hdr->body!=NULL ) {
513 memcpy( ptr, http_hdr->body, http_hdr->body_size ); 512 memcpy( ptr, http_hdr->body, http_hdr->body_size );
514 } 513 }
515 514
516 if( uri ) free( uri ); 515 free(uri);
517 return http_hdr->buffer; 516 return http_hdr->buffer;
518 } 517 }
519 518
520 char * 519 char *
521 http_get_field( HTTP_header_t *http_hdr, const char *field_name ) { 520 http_get_field( HTTP_header_t *http_hdr, const char *field_name ) {