Skip to content
  • Thomas Haller's avatar
    all: avoid calling g_free on a const pointer with g_clear_pointer() · f0442a47
    Thomas Haller authored
    With g_clear_pointer(pptr, g_free), pptr is cast to a non-const pointer,
    and hence there is no compiler warning about calling g_free() in a const
    pointer. However, it still feels ugly to pass a const pointer to
    g_clear_pointer(). We should either add an explicity cast, or just
    make the pointer non-const.
    
    I guess part of the problem is that C's "const char *" means that the
    string itself is immutable, but also that it cannot be freed. We most
    often want a different semantic: the string itself is immutable after
    being initialized once, but the memory itself can and will be freed.
    Such a notion of immutable C strings cannot be expressed.
    
    For that, just remove the "const" from the declarations. Although we
    don't want to modify the (content of the) string, it's still more a
    mutable string.
    
    Only in _vt_cmd_obj_copy_lnk_vlan(), add an explicity cast but keep the
    type as const. The reason is, that we really want that NMPObject
    instances are immutable (in the sense that they don't modify while
    existing), but that doesn't mean the memory cannot be freed.
    f0442a47