diff options
author | bertrand <Bertrand.Guiheneuf@aful.org> | 1999-08-11 07:22:44 +0800 |
---|---|---|
committer | Bertrand Guiheneuf <bertrand@src.gnome.org> | 1999-08-11 07:22:44 +0800 |
commit | 9d041c9464b7e13cce7368e644781971d9ad5501 (patch) | |
tree | a7671cef07919885cb61baa31cade7bdccaa7a1e /camel/gmime-content-field.c | |
parent | 7d7f5423308313eb30558700598091b4ba1f0d20 (diff) | |
download | gsoc2013-evolution-9d041c9464b7e13cce7368e644781971d9ad5501.tar.gz gsoc2013-evolution-9d041c9464b7e13cce7368e644781971d9ad5501.tar.zst gsoc2013-evolution-9d041c9464b7e13cce7368e644781971d9ad5501.zip |
implemented destructors.
1999-08-11 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/camel-multipart.c (_finalize):
* camel/camel-simple-data-wrapper.c (_finalize):
* camel/camel-mime-part.c (_finalize):
implemented destructors.
* camel/gmime-content-field.c (gmime_content_field_ref):
(gmime_content_field_unref):
New reference mechanism for GMimeContentField objects.
* camel/camel-data-wrapper.c (_finalize):
Started implementing destructors.
* camel/camel-mime-part.c (_construct_from_stream):
* camel/gmime-content-field.c (gmime_content_field_write_to_stream):
* camel/camel-multipart.c (_construct_from_stream):
removed forgotten anarchic traces.
Go away memory leaks!
svn path=/trunk/; revision=1103
Diffstat (limited to 'camel/gmime-content-field.c')
-rw-r--r-- | camel/gmime-content-field.c | 81 |
1 files changed, 62 insertions, 19 deletions
diff --git a/camel/gmime-content-field.c b/camel/gmime-content-field.c index 285926e702..04b07b7626 100644 --- a/camel/gmime-content-field.c +++ b/camel/gmime-content-field.c @@ -50,11 +50,72 @@ gmime_content_field_new (const gchar *type, const gchar *subtype) ctf->type = g_strdup (type); ctf->subtype = g_strdup (subtype); ctf->parameters = g_hash_table_new (g_str_hash, g_str_equal); - + ctf->ref = 1; + return ctf; } +static void +_free_parameter (gpointer name, gpointer value, gpointer user_data) +{ + g_free (name); + g_free (value); +} + +/** + * gmime_content_field_free: free a GMimeContentField object + * @content_field: GMimeContentField object + * + * This method destroys the object and should be used very carefully. + * Use gmime_content_field_unref instead. + * + **/ +void +gmime_content_field_free (GMimeContentField *content_field) +{ + g_hash_table_foreach (content_field->parameters, _free_parameter, NULL); + g_free (content_field->type); + g_free (content_field->subtype); + g_hash_table_destroy (content_field->parameters); + g_free (content_field); +} + +/** + * gmime_content_field_ref: add a reference to a GMimeContentField object + * @content_field: GMimeContentField object + * + * Tell a GMimeContentField object that something holds a reference + * on him. This, coupled with the corresponding + * gmime_content_field_unref() method allow several + * objects to use the same GMimeContentField object. + **/ +void +gmime_content_field_ref (GMimeContentField *content_field) +{ + content_field->ref += 1; +} + +/** + * gmime_content_field_unref: remove a reference to a GMimeContentField object + * @content_field: GMimeContentField object + * + * Tell a GMimeContentField object that something which + * was holding a reference to him does not need it anymore. + * When no more reference exist, the GMimeContentField object + * is freed using gmime_content_field_free(). + * + **/ +void +gmime_content_field_unref (GMimeContentField *content_field) +{ + content_field->ref -= 1; + if (content_field->ref <= 0) + gmime_content_field_free (content_field); +} + + + /** * gmime_content_field_set_parameter: set a parameter for a GMimeContentField object * @content_field: content field @@ -125,7 +186,6 @@ gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStre if (!content_field) return; g_assert (stream); - printf ("Content-field address = %p\n", content_field); if (content_field->type) { camel_stream_write_strings (stream, "Content-Type: ", content_field->type, NULL); if (content_field->subtype) { @@ -304,20 +364,3 @@ gmime_content_field_construct_from_string (GMimeContentField *content_field, con } - -static void -_free_parameter (gpointer name, gpointer value, gpointer user_data) -{ - g_free (name); - g_free (value); -} - -void -gmime_content_field_free (GMimeContentField *content_field) -{ - g_hash_table_foreach (content_field->parameters, _free_parameter, NULL); - g_free (content_field->type); - g_free (content_field->subtype); - g_hash_table_destroy (content_field->parameters); - g_free (content_field); -} |