summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar m0gg2007-11-04 08:41:20 +0000
committerGravatar m0gg2007-11-04 08:41:20 +0000
commitb878e1a8b596b377077312a334704bc14f247636 (patch)
tree6d362014d94b63fac7415d791fde67a0cc2df653
parentc05be50d9b0e292fad30531eaf98507ba2b95d57 (diff)
downloadcsoap-b878e1a8b596b377077312a334704bc14f247636.tar.gz
csoap-b878e1a8b596b377077312a334704bc14f247636.tar.bz2
Fixed a memleak
-rwxr-xr-xnanohttp/nanohttp-stream.c40
1 files changed, 15 insertions, 25 deletions
diff --git a/nanohttp/nanohttp-stream.c b/nanohttp/nanohttp-stream.c
index 64c066c..466b21a 100755
--- a/nanohttp/nanohttp-stream.c
+++ b/nanohttp/nanohttp-stream.c
@@ -1,6 +1,6 @@
/** @file nanohttp-stream.c Stream handling */
/******************************************************************
-* $Id: nanohttp-stream.c,v 1.20 2007/11/03 22:40:15 m0gg Exp $
+* $Id: nanohttp-stream.c,v 1.21 2007/11/04 08:41:20 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -52,12 +52,8 @@
#include "nanohttp-socket.h"
#include "nanohttp-stream.h"
-/*------------------------------------------------------------
-HTTP INPUT STREAM
-------------------------------------------------------------*/
-
static int
-_http_stream_is_content_length(hpair_t * header)
+_http_stream_has_content_length(hpair_t * header)
{
return hpairnode_get_ignore_case(header, HEADER_CONTENT_LENGTH) != NULL;
}
@@ -66,6 +62,7 @@ static int
_http_stream_is_chunked(hpair_t * header)
{
char *chunked;
+
chunked = hpairnode_get_ignore_case(header, HEADER_TRANSFER_ENCODING);
if (chunked != NULL)
{
@@ -74,7 +71,6 @@ _http_stream_is_chunked(hpair_t * header)
return 1;
}
}
-
return 0;
}
@@ -99,7 +95,7 @@ http_input_stream_new(struct hsocket_t *sock, hpair_t * header)
/* Find connection type */
hpairnode_dump_deep(header);
/* Check if Content-type */
- if (_http_stream_is_content_length(header))
+ if (_http_stream_has_content_length(header))
{
log_verbose("Stream transfer with 'Content-length'");
content_length = hpairnode_get_ignore_case(header, HEADER_CONTENT_LENGTH);
@@ -153,6 +149,7 @@ http_input_stream_new_from_file(const char *filename)
result->type = HTTP_TRANSFER_FILE;
result->fd = fd;
+ result->err = H_OK;
result->deleteOnExit = 0;
strcpy(result->filename, filename);
@@ -170,6 +167,9 @@ http_input_stream_free(struct http_input_stream_t * stream)
/* remove(stream->filename); */
}
+ if (stream->err)
+ herror_release(stream->err);
+
free(stream);
}
@@ -427,6 +427,8 @@ http_input_stream_is_ready(struct http_input_stream_t * stream)
return 0;
/* reset error flag */
+ if (stream->err)
+ herror_release(stream->err);
stream->err = H_OK;
switch (stream->type)
@@ -442,7 +444,6 @@ http_input_stream_is_ready(struct http_input_stream_t * stream)
default:
return 0;
}
-
}
/**
@@ -453,13 +454,14 @@ int
http_input_stream_read(struct http_input_stream_t * stream, unsigned char *dest, int size)
{
int len = 0;
+
/* paranoia check */
if (stream == NULL)
- {
return -1;
- }
- /* XXX: possible memleak! reset error flag */
+ /* reset error flag */
+ if (stream->err)
+ herror_release(stream->err);
stream->err = H_OK;
switch (stream->type)
@@ -482,21 +484,9 @@ http_input_stream_read(struct http_input_stream_t * stream, unsigned char *dest,
"%d is invalid stream type", stream->type);
return -1;
}
-
return len;
}
-
-/*
--------------------------------------------------------------------
-
-HTTP OUTPUT STREAM
-
--------------------------------------------------------------------
-*/
-
-
-
/**
Creates a new output stream. Transfer code will be found from header.
*/
@@ -523,7 +513,7 @@ http_output_stream_new(struct hsocket_t *sock, hpair_t * header)
/* Find connection type */
/* Check if Content-type */
- if (_http_stream_is_content_length(header))
+ if (_http_stream_has_content_length(header))
{
log_verbose("Stream transfer with 'Content-length'");
content_length = hpairnode_get_ignore_case(header, HEADER_CONTENT_LENGTH);