This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

wireshark source file diam_dict.l

0

In the source file of Wireshark, in the file "diam_dict.l" (parser for diameter protocol dictionary), I found the following function:

void
ddict_free(ddict_t* d)
{
    ddict_application_t *p, *pn;
    ddict_vendor_t *v, *vn;
    ddict_cmd_t *c, *cn;
    ddict_typedefn_t *t, *tn;
    ddict_avp_t *a, *an;

#define FREE_NAMEANDOBJ(n) do { if(n->name) g_free(n->name); g_free(n); } while(0)

for (p = d->applications; p; p = pn ) {
    pn = p->next;
    FREE_NAMEANDOBJ(p);
}

for (v = d->vendors; v; v = vn) {
    vn = v->next;
    if (!v->desc)  g_free(v->desc);
    FREE_NAMEANDOBJ(v);
}

for (c = d->cmds; c; c = cn ) {
    cn = c->next;
    FREE_NAMEANDOBJ(c);
}

for (t = d->typedefns; t; t = tn) {
    tn = t->next;
    if (!t->parent)  g_free(t->parent);
    FREE_NAMEANDOBJ(t);
}

for (a = d->avps; a; a = an) {
    ddict_gavp_t* g, *gn;
    ddict_enum_t* e, *en;
    an = a->next;

    for (g = a->gavps; g; g = gn) {
        gn = g->next;
        FREE_NAMEANDOBJ(g);
    }

    for (e = a->enums; e; e = en) {
        en = e->next;
        FREE_NAMEANDOBJ(e);
    }

    if (!a->vendor)  g_free(a->vendor);
    if (!a->type)  g_free(a->type);
    if (!a->description)  g_free(a->description);
    FREE_NAMEANDOBJ(a);
}

g_free(d);

}



I wonder why we are using

if (!v->desc)  g_free(v->desc);
if (!t->parent)  g_free(t->parent);
if (!a->vendor)  g_free(a->vendor);
if (!a->type)  g_free(a->type);
if (!a->description)  g_free(a->description);

instead of using

if (v->desc)  g_free(v->desc);
if (t->parent)  g_free(t->parent);
if (a->vendor)  g_free(a->vendor);
if (a->type)  g_free(a->type);
if (a->description)  g_free(a->description);

I think, we should use g_free to free a non-null pointer, but it seems that in the source code, we are freeing a null pointer, so what is the reason for this ?

asked 07 Jun '16, 08:47

bohao's gravatar image

bohao
16226
accept rate: 0%


One Answer:

1

what is the reason for this

The reason is that somebody typed "!" when they shouldn't have. Please file a bug on this on the Wireshark Bugzilla.

answered 07 Jun '16, 12:55

Guy%20Harris's gravatar image

Guy Harris ♦♦
17.4k335196
accept rate: 19%

When you do, please be sure to reference this question in the bug and then report the bug number back here.

Side note: this is dead code that's never called--ddict_free() is never, AFAICS, called.

(07 Jun '16, 13:04) JeffMorriss ♦

Of course I know that that main function of this file is never called unless we want to do tests. I used the compiled file "diam_dict.c" to parse the Diameter Protocol dictionary (a xml file in the source code of Wireshark) and then I found this problem. In fact, there are also some problems in the Diameter Protocol related dicitonaries (XML documents in ther directory wireshark-2.0.3/diameter), I will then report all these problems.

(07 Jun '16, 13:45) bohao

Note that I wasn't talking about the main program but ddict_free()--it's not called, even by the (test) main program.

(07 Jun '16, 14:10) JeffMorriss ♦

Sorry, I mistook it cause I thought ddict_free() will be called in the main function and obviously it is not. Yeah, you are right, it's never called.

(07 Jun '16, 14:33) bohao

Bug 12497, now fixed.

(07 Jun '16, 14:50) Guy Harris ♦♦