[gmime-devel] GObject unref hell



Hello,

i'm currently in the process of using GMime for a mail process application. First of all i'd like to thank Jeffrey and potential other contributors to GMime for writing this wonderful library, as MIME parsing and generating is everything but fun.

I find myself with a problem that i can't seem to wrap my head around.
The following code snippet deterministically works in some instances, but not in others.

#define rfunref(obj) if (obj) { if G_IS_OBJECT(obj) { \
    g_debug("[%s:%d] unref "#obj, __FILE__, __LINE__); \
    g_object_unref(obj); obj = NULL; \
    g_debug("[%s:%d] unrefed "#obj, __FILE__, __LINE__); }}

  GMimeDataWrapper *content = NULL;
  GMimeStream *mem = NULL;
  GMimePart *part = NULL;
  GMimeMultipart *multipart = NULL;
  char *fileName = NULL;
  char *type = NULL, *subtype = NULL, *param = NULL, *value = NULL;

  do{
    /* other stuff here */

    /* set type, subtype, filename, etc. */
    /* find type */
    getType(msg, res, resLen, &type, &subtype, &param, &value);
    part = g_mime_part_new_with_type(type, subtype);
    g_mime_part_set_filename(part, fileName);
    g_mime_object_set_content_type_parameter((GMimeObject*)part,
                                              param, value);
    if (g_ascii_strcasecmp(type, "text") == 0) {
        g_mime_part_set_content_encoding(
                part, GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE);
    } else {
        g_mime_part_set_content_encoding (
                part, GMIME_CONTENT_ENCODING_BASE64);
    }
    g_mime_part_set_content_object (part, content);
    rfunref (content);

    g_mime_multipart_add (multipart, (GMimeObject *) part);
    rfunref (part);
  } while(attachments);

  g_mime_message_set_mime_part (message, (GMimeObject*) multipart);
  headerList = g_mime_object_get_header_list((GMimeObject*)multipart);
  rfunref (multipart);


A failed event looks like this

VERB: successfully extracted mime type: [application] subtype: [octet-stream] param: [charset] value: [binary]
VERB: [mime.c:270] unref content
VERB: [mime.c:270] unrefed content
VERB: [mime.c:273] unref part
VERB: [mime.c:273] unrefed part

(process:9549): GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' failed
VERB: [mime.c:280] unref multipart
VERB: [mime.c:280] unrefed multipart

while a good one looks like

VERB: successfully extracted mime type: [text] subtype: [plain] param: [charset] value: [utf-8]
VERB: [mime.c:270] unref content
VERB: [mime.c:270] unrefed content
VERB: [mime.c:273] unref part
VERB: [mime.c:273] unrefed part
VERB: [mime.c:280] unref multipart
VERB: [mime.c:280] unrefed multipart

The unref macro is a mere act of desperation.

I have 2 general questions here.
1. What is going on here. No code was skipped between unref part and multipart. 2. Is there a way to safely unref a GObject, i.e. unref it if it needs to be? This is mainly because it is not always clear to me when and when not due to issues like the current.

Clue sticks to either question would be greatly appreciated.

--
Mit Freundlichen Grüßen / Regards

Mario Theodoridis

regify®
your mail matters


regify S.A. | 2b, Ennert dem Bierg | L-5244 Sandweiler / Luxembourg

phone: +352 268 9321 | internet: www.regify.com
executive board: Kurt Kammerer, Volker Schmid
supervisory board chairman: Dr. Hans-Peter Kohlhammer
commercial register: Registre de Commerce et des Sociétés B 156705


regify GmbH | Römerstrasse 39 | D-78183 Hüfingen / Germany

Telefon: +49 771 8978 4238 | Internet: www.regify.com
Geschäftsführung: Kurt Kammerer, Volker Schmid
Handelsregister: Amtsgericht Freiburg HRB 709343


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]