return the number of bytes read. How can this have ever worked ?

1999-08-17  bertrand  <Bertrand.Guiheneuf@aful.org>

	* camel/camel-stream.c (camel_stream_read):
	return the number of bytes read.
	How can this have ever worked ?
	(camel_stream_flush): don't return anything.

	* camel/gmime-utils.c (get_header_table_from_stream):
	mem leak fixed.

+ various other mem leaks.

svn path=/trunk/; revision=1120
This commit is contained in:
bertrand
1999-08-17 17:44:00 +00:00
committed by Bertrand Guiheneuf
parent 8efa5bea54
commit 08752e1b53
9 changed files with 51 additions and 20 deletions

View File

@ -1,3 +1,13 @@
1999-08-17 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/camel-stream.c (camel_stream_read):
return the number of bytes read.
How can this have ever worked ?
(camel_stream_flush): don't return anything.
* camel/gmime-utils.c (get_header_table_from_stream):
mem leak fixed.
1999-08-16 bertrand <Bertrand.Guiheneuf@aful.org> 1999-08-16 bertrand <Bertrand.Guiheneuf@aful.org>
* tests/ui-tests/store_listing.c: * tests/ui-tests/store_listing.c:

View File

@ -220,7 +220,7 @@ _remove_part_at (CamelMultipart *multipart, guint index)
if (!(multipart->parts)) { if (!(multipart->parts)) {
CAMEL_LOG_FULL_DEBUG ("CamelMultipart::remove_part_at part list is void \n"); CAMEL_LOG_FULL_DEBUG ("CamelMultipart::remove_part_at part list is void \n");
return; return NULL;
} }
parts_list = multipart->parts; parts_list = multipart->parts;
@ -337,7 +337,7 @@ _get_boundary (CamelMultipart *multipart)
CAMEL_LOG_FULL_DEBUG ("Entering CamelMultipart::_get_boundary\n"); CAMEL_LOG_FULL_DEBUG ("Entering CamelMultipart::_get_boundary\n");
if (!CAMEL_DATA_WRAPPER (multipart)->mime_type) { if (!CAMEL_DATA_WRAPPER (multipart)->mime_type) {
CAMEL_LOG_WARNING ("CamelMultipart::_get_boundary CAMEL_DATA_WRAPPER (multipart)->mime_type is NULL\n"); CAMEL_LOG_WARNING ("CamelMultipart::_get_boundary CAMEL_DATA_WRAPPER (multipart)->mime_type is NULL\n");
return; return NULL;
} }
boundary = gmime_content_field_get_parameter (CAMEL_DATA_WRAPPER (multipart)->mime_type, "boundary"); boundary = gmime_content_field_get_parameter (CAMEL_DATA_WRAPPER (multipart)->mime_type, "boundary");
CAMEL_LOG_FULL_DEBUG ("Leaving CamelMultipart::_get_boundary\n"); CAMEL_LOG_FULL_DEBUG ("Leaving CamelMultipart::_get_boundary\n");
@ -415,7 +415,7 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
static gboolean static gboolean
_read_part (CamelStream *new_part_stream, CamelStream *stream, gchar *normal_boundary, gchar *end_boundary) _read_part (CamelStream *new_part_stream, CamelStream *stream, gchar *normal_boundary, gchar *end_boundary)
{ {
gchar *new_line; gchar *new_line = NULL;
gboolean end_of_part = FALSE; gboolean end_of_part = FALSE;
gboolean last_part = FALSE; gboolean last_part = FALSE;
gboolean first_line = TRUE; gboolean first_line = TRUE;
@ -436,10 +436,12 @@ _read_part (CamelStream *new_part_stream, CamelStream *stream, gchar *normal_bou
first_line = FALSE; first_line = FALSE;
camel_stream_write_string (new_part_stream, new_line); camel_stream_write_string (new_part_stream, new_line);
} else camel_stream_write_strings (new_part_stream, "\n", new_line, NULL); } else camel_stream_write_strings (new_part_stream, "\n", new_line, NULL);
g_free (new_line);
new_line = gmime_read_line_from_stream (stream); new_line = gmime_read_line_from_stream (stream);
} }
} }
if (new_line) g_free (new_line);
CAMEL_LOG_FULL_DEBUG ("CamelMultipart:: Leaving _read_part\n"); CAMEL_LOG_FULL_DEBUG ("CamelMultipart:: Leaving _read_part\n");
return (last_part || (new_line == NULL)); return (last_part || (new_line == NULL));
} }
@ -466,7 +468,8 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
/* read the prefix if any */ /* read the prefix if any */
new_part_stream = camel_stream_mem_new (CAMEL_STREAM_MEM_RW); new_part_stream = camel_stream_mem_new (CAMEL_STREAM_MEM_RW);
end_of_multipart = _read_part (new_part_stream, stream, real_boundary_line, end_boundary_line); end_of_multipart = _read_part (new_part_stream, stream, real_boundary_line, end_boundary_line);
gtk_object_destroy (GTK_OBJECT (new_part_stream)); CAMEL_LOG_FULL_DEBUG ("CamelMultipart::construct_from_stream freeing new_part_stream:%p\n", new_part_stream);
gtk_object_unref (GTK_OBJECT (new_part_stream));
if (multipart->preface) g_free (multipart->preface); if (multipart->preface) g_free (multipart->preface);
//if ( (new_part->str)[0] != '\0') multipart->preface = g_strdup (new_part->str); //if ( (new_part->str)[0] != '\0') multipart->preface = g_strdup (new_part->str);

View File

@ -159,7 +159,7 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
g_byte_array_free (array, FALSE); g_byte_array_free (array, FALSE);
} }
array = g_byte_array_new(); array = g_byte_array_new ();
CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::construct_from_stream new byte array address:%p\n", array); CAMEL_LOG_FULL_DEBUG ("CamelSimpleDataWrapper::construct_from_stream new byte array address:%p\n", array);
simple_data_wrapper->byte_array = array; simple_data_wrapper->byte_array = array;
nb_bytes_read = camel_stream_read (stream, tmp_buf, _CMSDW_TMP_BUF_SIZE); nb_bytes_read = camel_stream_read (stream, tmp_buf, _CMSDW_TMP_BUF_SIZE);

View File

@ -66,7 +66,7 @@ camel_stream_fs_class_init (CamelStreamFsClass *camel_stream_fs_class)
camel_stream_class->seek = _seek; camel_stream_class->seek = _seek;
gtk_object_class->finalize = _finalize; gtk_object_class->finalize = _finalize;
gtk_object_class->finalize = _destroy; gtk_object_class->destroy = _destroy;
} }
@ -111,6 +111,7 @@ _destroy (GtkObject *object)
CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno)); CAMEL_LOG_FULL_DEBUG ( " Full error text is : %s\n", strerror(errno));
} }
GTK_OBJECT_CLASS (parent_class)->destroy (object); GTK_OBJECT_CLASS (parent_class)->destroy (object);
g_free (object);
CAMEL_LOG_FULL_DEBUG ("Leaving CamelStreamFs::destroy\n"); CAMEL_LOG_FULL_DEBUG ("Leaving CamelStreamFs::destroy\n");
} }
@ -194,10 +195,12 @@ camel_stream_fs_new_with_fd (int fd)
static gint static gint
_read (CamelStream *stream, gchar *buffer, gint n) _read (CamelStream *stream, gchar *buffer, gint n)
{ {
int v; gint v;
do { do {
v = read ( (CAMEL_STREAM_FS (stream))->fd, buffer, n); v = read ( (CAMEL_STREAM_FS (stream))->fd, buffer, n);
} while (v == -1 && errno == EINTR); } while (v == -1 && errno == EINTR);
if (v<0)
CAMEL_LOG_FULL_DEBUG ("CamelStreamFs::read v=%d\n", v);
return v; return v;
} }

View File

@ -104,7 +104,7 @@ camel_stream_get_type (void)
gint gint
camel_stream_read (CamelStream *stream, gchar *buffer, gint n) camel_stream_read (CamelStream *stream, gchar *buffer, gint n)
{ {
CS_CLASS (stream)->read (stream, buffer, n); return CS_CLASS (stream)->read (stream, buffer, n);
} }
/** /**
@ -133,7 +133,7 @@ camel_stream_write (CamelStream *stream, const gchar *buffer, gint n)
void void
camel_stream_flush (CamelStream *stream) camel_stream_flush (CamelStream *stream)
{ {
return CS_CLASS (stream)->flush (stream); CS_CLASS (stream)->flush (stream);
} }
/** /**

View File

@ -126,7 +126,7 @@ gmime_content_field_unref (GMimeContentField *content_field)
* or valid parameters name depend on the content type object. For example, * or valid parameters name depend on the content type object. For example,
* gmime_content_field_set_parameter (cf, "charset", "us-ascii"); * gmime_content_field_set_parameter (cf, "charset", "us-ascii");
* will make sense for a "text/plain" content field but not for a * will make sense for a "text/plain" content field but not for a
* "image/gif". This routine does not check parameter validuty. * "image/gif". This routine does not check parameter validity.
**/ **/
void void
gmime_content_field_set_parameter (GMimeContentField *content_field, const gchar *attribute, const gchar *value) gmime_content_field_set_parameter (GMimeContentField *content_field, const gchar *attribute, const gchar *value)
@ -356,6 +356,8 @@ gmime_content_field_construct_from_string (GMimeContentField *content_field, con
CAMEL_LOG_TRACE ( "GMimeContentField::construct_from_string, Found mime parameter \"%s\"=\"%s\"\n", param_name, param_value); CAMEL_LOG_TRACE ( "GMimeContentField::construct_from_string, Found mime parameter \"%s\"=\"%s\"\n", param_name, param_value);
string_trim (param_value, " \t", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING); string_trim (param_value, " \t", STRING_TRIM_STRIP_TRAILING | STRING_TRIM_STRIP_LEADING);
gmime_content_field_set_parameter (content_field, param_name, param_value); gmime_content_field_set_parameter (content_field, param_name, param_value);
g_free (param_name);
g_free (param_value);
i++; i++;
first = i; first = i;
} }

View File

@ -113,6 +113,8 @@ _store_header_pair_from_string (GHashTable *header_table, gchar *header_line)
{ {
gchar dich_result; gchar dich_result;
gchar *header_name, *header_value; gchar *header_name, *header_value;
gboolean key_exists;
gchar *old_header_name, *old_header_value;
CAMEL_LOG_FULL_DEBUG ( "_store_header_pair_from_string:: Entering\n"); CAMEL_LOG_FULL_DEBUG ( "_store_header_pair_from_string:: Entering\n");
g_assert (header_table); g_assert (header_table);
@ -121,15 +123,23 @@ _store_header_pair_from_string (GHashTable *header_table, gchar *header_line)
dich_result = string_dichotomy ( header_line, ':', dich_result = string_dichotomy ( header_line, ':',
&header_name, &header_value, &header_name, &header_value,
STRING_DICHOTOMY_NONE); STRING_DICHOTOMY_NONE);
if (dich_result != 'o') if (dich_result != 'o') {
CAMEL_LOG_WARNING ( CAMEL_LOG_WARNING (
"** WARNING **\n" "** WARNING **\n"
"store_header_pair_from_string : dichotomy result is '%c'\n" "store_header_pair_from_string : dichotomy result is '%c'\n"
"header line is :\n--\n%s\n--\n" "header line is :\n--\n%s\n--\n"
"** \n", dich_result, header_line); "** \n", dich_result, header_line);
else { if (header_name)
g_free (header_name);
if (header_value)
g_free (header_value);
} else {
string_trim (header_value, " \t", string_trim (header_value, " \t",
STRING_TRIM_STRIP_LEADING | STRING_TRIM_STRIP_TRAILING); STRING_TRIM_STRIP_LEADING | STRING_TRIM_STRIP_TRAILING);
key_exists = g_hash_table_lookup_extended (header_table, header_name, &old_header_name, &old_header_name);
if (key_exists)
printf ("-------- Key %s already exists /n", header_name);
g_hash_table_insert (header_table, header_name, header_value); g_hash_table_insert (header_table, header_name, header_value);
} }
} }
@ -186,9 +196,8 @@ get_header_table_from_stream (CamelStream *stream)
} }
default: default:
if (!crlf) header_line = g_string_append_c (header_line, next_char); if (!crlf) header_line = g_string_append_c (header_line, next_char);
else end_of_header_line = TRUE;
else end_of_header_line = TRUE;
} }
} else { } else {
end_of_file=TRUE; end_of_file=TRUE;
@ -201,8 +210,8 @@ else end_of_header_line = TRUE;
} while ( !end_of_header_line ); } while ( !end_of_header_line );
if ( strlen(header_line->str) ) { if ( strlen(header_line->str) ) {
str_header_line = g_strdup (header_line->str); /* str_header_line = g_strdup (header_line->str); */
_store_header_pair_from_string (header_table, str_header_line); _store_header_pair_from_string (header_table, header_line->str);
} }
g_string_free (header_line, FALSE); g_string_free (header_line, FALSE);

View File

@ -136,11 +136,11 @@ string_dichotomy (const gchar *string, gchar sep, gchar **prefix, gchar **suffix
} }
CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator found at :%d\n", sep_pos); CAMEL_LOG_FULL_DEBUG ("string_dichotomy: separator found at :%d\n", sep_pos);
if (prefix) { /* return the prefix */ if (prefix) { /* return the prefix */
*prefix = g_strndup(string+first,sep_pos-first); *prefix = g_strndup (string+first,sep_pos-first);
CAMEL_LOG_FULL_DEBUG ( "string_dichotomy:: prefix:\"%s\"\n", *prefix); CAMEL_LOG_FULL_DEBUG ( "string_dichotomy:: prefix:\"%s\"\n", *prefix);
} }
if (suffix) { /* return the suffix */ if (suffix) { /* return the suffix */
*suffix = g_strndup(string+sep_pos+1, last-sep_pos); *suffix = g_strndup (string+sep_pos+1, last-sep_pos);
CAMEL_LOG_FULL_DEBUG ( "string_dichotomy:: suffix:\"%s\"\n", *suffix); CAMEL_LOG_FULL_DEBUG ( "string_dichotomy:: suffix:\"%s\"\n", *suffix);
} }

View File

@ -32,10 +32,14 @@ main (int argc, char**argv)
camel_data_wrapper_construct_from_stream ( CAMEL_DATA_WRAPPER (message), input_stream); camel_data_wrapper_construct_from_stream ( CAMEL_DATA_WRAPPER (message), input_stream);
camel_stream_close (input_stream); camel_stream_close (input_stream);
gtk_object_unref (GTK_OBJECT (input_stream));
output_stream = camel_stream_fs_new_with_name ("mail2.test", CAMEL_STREAM_FS_WRITE); output_stream = camel_stream_fs_new_with_name ("mail2.test", CAMEL_STREAM_FS_WRITE);
camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), output_stream); camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), output_stream);
camel_stream_close (output_stream); camel_stream_close (output_stream);
gtk_object_unref (GTK_OBJECT (output_stream));
gtk_object_unref (GTK_OBJECT (message));
return 0; return 0;