Ticket #273: ticket273.patch

File ticket273.patch, 22.0 KB (added by Petr Koupy, 13 years ago)
  • uspace/lib/c/generic/net/packet.c

    # Bazaar merge directive format 2 (Bazaar 0.90)
    # revision_id: petr.koupy@gmail.com-20110328003358-figohl0siqh1j288
    # target_branch: bzr://bzr.helenos.org/mainline
    # testament_sha1: 75d9dab3c202f95b9a28b5a3c742cd8ba14a6e8f
    # timestamp: 2011-03-28 02:36:28 +0200
    # base_revision_id: jakub@jermar.eu-20110326152906-4nqf7cc7vwgs62cc
    # 
    # Begin patch
    === modified file 'uspace/lib/c/generic/net/packet.c'
     
    189189                                munmap(packet, packet->length);
    190190                }
    191191        }
    192         gpm_destroy(&pm_globals.packet_map);
     192        gpm_destroy(&pm_globals.packet_map, free);
    193193        /* leave locked */
    194194}
    195195
  • uspace/lib/c/generic/net/socket_client.c

    === modified file 'uspace/lib/c/generic/net/socket_client.c'
     
    748748
    749749        dyn_fifo_destroy(&socket->received);
    750750        dyn_fifo_destroy(&socket->accepted);
    751         sockets_exclude(socket_get_sockets(), socket->socket_id);
     751        sockets_exclude(socket_get_sockets(), socket->socket_id, free);
    752752}
    753753
    754754/** Closes the socket.
  • uspace/lib/c/include/adt/generic_char_map.h

    === modified file 'uspace/lib/c/include/adt/generic_char_map.h'
     
    4646/** Internal magic value for a map consistency check. */
    4747#define GENERIC_CHAR_MAP_MAGIC_VALUE    0x12345622
    4848
     49/** Generic destructor function pointer. */
     50#define DTOR_T(identifier) \
     51        void (*identifier)(const void *)
     52
    4953/** Character string to generic type map declaration.
    5054 *  @param[in] name     Name of the map.
    5155 *  @param[in] type     Inner object type.
     
    6367        \
    6468        int name##_add(name##_t *, const uint8_t *, const size_t, type *); \
    6569        int name##_count(name##_t *); \
    66         void name##_destroy(name##_t *); \
    67         void name##_exclude(name##_t *, const uint8_t *, const size_t); \
     70        void name##_destroy(name##_t *, DTOR_T()); \
     71        void name##_exclude(name##_t *, const uint8_t *, const size_t, DTOR_T()); \
    6872        type *name##_find(name##_t *, const uint8_t *, const size_t); \
    6973        int name##_initialize(name##_t *); \
    7074        int name##_is_valid(name##_t *);
     
    8387        int name##_add(name##_t *map, const uint8_t *name, const size_t length, \
    8488             type *value) \
    8589        { \
    86                 int rc; \
    8790                int index; \
    8891                if (!name##_is_valid(map)) \
    8992                        return EINVAL; \
    9093                index = name##_items_add(&map->values, value); \
    9194                if (index < 0) \
    9295                        return index; \
    93                 rc = char_map_add(&map->names, name, length, index); \
    94                 if (rc != EOK) { \
    95                         name##_items_exclude_index(&map->values, index); \
    96                         return rc; \
    97                 } \
    98                 return EOK; \
     96                return char_map_add(&map->names, name, length, index); \
    9997        } \
    10098        \
    10199        int name##_count(name##_t *map) \
     
    104102                    name##_items_count(&map->values) : -1; \
    105103        } \
    106104        \
    107         void name##_destroy(name##_t *map) \
     105        void name##_destroy(name##_t *map, DTOR_T(dtor)) \
    108106        { \
    109107                if (name##_is_valid(map)) { \
    110108                        char_map_destroy(&map->names); \
    111                         name##_items_destroy(&map->values); \
     109                        name##_items_destroy(&map->values, dtor); \
    112110                } \
    113111        } \
    114112        \
    115113        void name##_exclude(name##_t *map, const uint8_t *name, \
    116             const size_t length) \
     114            const size_t length, DTOR_T(dtor)) \
    117115        { \
    118116                if (name##_is_valid(map)) { \
    119117                        int index; \
    120118                        index = char_map_exclude(&map->names, name, length); \
    121119                        if (index != CHAR_MAP_NULL) \
    122120                                name##_items_exclude_index(&map->values, \
    123                                      index); \
     121                                     index, dtor); \
    124122                } \
    125123        } \
    126124        \
  • uspace/lib/c/include/adt/generic_field.h

    === modified file 'uspace/lib/c/include/adt/generic_field.h'
     
    4545/** Internal magic value for a&nbsp;field consistency check. */
    4646#define GENERIC_FIELD_MAGIC_VALUE               0x55667788
    4747
     48/** Generic destructor function pointer. */
     49#define DTOR_T(identifier) \
     50        void (*identifier)(const void *)
     51
    4852/** Generic type field declaration.
    4953 *
    5054 * @param[in] name      Name of the field.
     
    6266        \
    6367        int name##_add(name##_t *, type *); \
    6468        int name##_count(name##_t *); \
    65         void name##_destroy(name##_t *); \
    66         void name##_exclude_index(name##_t *, int); \
     69        void name##_destroy(name##_t *, DTOR_T()); \
     70        void name##_exclude_index(name##_t *, int, DTOR_T()); \
    6771        type **name##_get_field(name##_t *); \
    6872        type *name##_get_index(name##_t *, int); \
    6973        int name##_initialize(name##_t *); \
     
    102106                return name##_is_valid(field) ? field->next : -1; \
    103107        } \
    104108        \
    105         void name##_destroy(name##_t *field) \
     109        void name##_destroy(name##_t *field, DTOR_T(dtor)) \
    106110        { \
    107111                if (name##_is_valid(field)) { \
    108112                        int index; \
    109113                        field->magic = 0; \
    110                         for (index = 0; index < field->next; index++) { \
    111                                 if (field->items[index]) \
    112                                         free(field->items[index]); \
     114                        if (dtor) { \
     115                                for (index = 0; index < field->next; index++) { \
     116                                        if (field->items[index]) \
     117                                                dtor(field->items[index]); \
     118                                } \
    113119                        } \
    114120                        free(field->items); \
    115121                } \
    116122        } \
    117123         \
    118         void name##_exclude_index(name##_t *field, int index) \
     124        void name##_exclude_index(name##_t *field, int index, DTOR_T(dtor)) \
    119125        { \
    120126                if (name##_is_valid(field) && (index >= 0) && \
    121127                    (index < field->next) && (field->items[index])) { \
    122                         free(field->items[index]); \
     128                        if (dtor) \
     129                                dtor(field->items[index]); \
    123130                        field->items[index] = NULL; \
    124131                } \
    125132        } \
  • uspace/lib/c/include/adt/int_map.h

    === modified file 'uspace/lib/c/include/adt/int_map.h'
     
    4848/** Internal magic value for an item consistency check. */
    4949#define INT_MAP_ITEM_MAGIC_VALUE        0x55667788
    5050
     51/** Generic destructor function pointer. */
     52#define DTOR_T(identifier) \
     53        void (*identifier)(const void *)
     54
    5155/** Integer to generic type map declaration.
    5256 *
    5357 * @param[in] name      Name of the map.
     
    7175        }; \
    7276        \
    7377        int name##_add(name##_t *, int, type *); \
    74         void name##_clear(name##_t *); \
     78        void name##_clear(name##_t *, DTOR_T()); \
    7579        int name##_count(name##_t *); \
    76         void name##_destroy(name##_t *); \
    77         void name##_exclude(name##_t *, int); \
    78         void name##_exclude_index(name##_t *, int); \
     80        void name##_destroy(name##_t *, DTOR_T()); \
     81        void name##_exclude(name##_t *, int, DTOR_T()); \
     82        void name##_exclude_index(name##_t *, int, DTOR_T()); \
    7983        type *name##_find(name##_t *, int); \
    8084        int name##_update(name##_t *, int, int); \
    8185        type *name##_get_index(name##_t *, int); \
    8286        int name##_initialize(name##_t *); \
    8387        int name##_is_valid(name##_t *); \
    84         void name##_item_destroy(name##_item_t *); \
     88        void name##_item_destroy(name##_item_t *, DTOR_T()); \
    8589        int name##_item_is_valid(name##_item_t *);
    8690
    8791/** Integer to generic type map implementation.
     
    114118                return EINVAL; \
    115119        } \
    116120        \
    117         void name##_clear(name##_t *map) \
     121        void name##_clear(name##_t *map, DTOR_T(dtor)) \
    118122        { \
    119123                if (name##_is_valid(map)) { \
    120124                        int index; \
    121125                        for (index = 0; index < map->next; ++index) { \
    122126                                if (name##_item_is_valid(&map->items[index])) { \
    123127                                        name##_item_destroy( \
    124                                             &map->items[index]); \
     128                                            &map->items[index], dtor); \
    125129                                } \
    126130                        } \
    127131                        map->next = 0; \
     
    134138                return name##_is_valid(map) ? map->next : -1; \
    135139        } \
    136140        \
    137         void name##_destroy(name##_t *map) \
     141        void name##_destroy(name##_t *map, DTOR_T(dtor)) \
    138142        { \
    139143                if (name##_is_valid(map)) { \
    140144                        int index; \
     
    142146                        for (index = 0; index < map->next; ++index) { \
    143147                                if (name##_item_is_valid(&map->items[index])) { \
    144148                                        name##_item_destroy( \
    145                                             &map->items[index]); \
     149                                            &map->items[index], dtor); \
    146150                                } \
    147151                        } \
    148152                        free(map->items); \
    149153                } \
    150154        } \
    151155        \
    152         void name##_exclude(name##_t *map, int key) \
     156        void name##_exclude(name##_t *map, int key, DTOR_T(dtor)) \
    153157        { \
    154158                if (name##_is_valid(map)) { \
    155159                        int index; \
     
    157161                                if (name##_item_is_valid(&map->items[index]) && \
    158162                                    (map->items[index].key == key)) { \
    159163                                        name##_item_destroy( \
    160                                             &map->items[index]); \
     164                                            &map->items[index], dtor); \
    161165                                } \
    162166                        } \
    163167                } \
    164168        } \
    165169        \
    166         void name##_exclude_index(name##_t *map, int index) \
     170        void name##_exclude_index(name##_t *map, int index, DTOR_T(dtor)) \
    167171        { \
    168172                if (name##_is_valid(map) && (index >= 0) && \
    169173                    (index < map->next) && \
    170174                    name##_item_is_valid(&map->items[index])) { \
    171                         name##_item_destroy(&map->items[index]); \
     175                        name##_item_destroy(&map->items[index], dtor); \
    172176                } \
    173177        } \
    174178        \
     
    235239                return map && (map->magic == INT_MAP_MAGIC_VALUE); \
    236240        } \
    237241        \
    238         void name##_item_destroy(name##_item_t *item) \
     242        void name##_item_destroy(name##_item_t *item, DTOR_T(dtor)) \
    239243        { \
    240244                if (name##_item_is_valid(item)) { \
    241245                        item->magic = 0; \
    242246                        if (item->value) { \
    243                                 free(item->value); \
     247                                if (dtor) \
     248                                        free(item->value); \
    244249                                item->value = NULL; \
    245250                        } \
    246251                } \
  • uspace/lib/net/tl/socket_core.c

    === modified file 'uspace/lib/net/tl/socket_core.c'
     
    106106        if (socket_release)
    107107                socket_release(socket);
    108108
    109         socket_cores_exclude(local_sockets, socket->socket_id);
     109        socket_cores_exclude(local_sockets, socket->socket_id, free);
    110110}
    111111
    112112/** Destroys local sockets.
     
    229229        return EOK;
    230230
    231231fail:
    232         socket_port_map_destroy(&socket_port->map);
     232        socket_port_map_destroy(&socket_port->map, free);
    233233        free(socket_port);
    234234        return rc;
    235235       
     
    648648                        // release if empty
    649649                        if (socket_port->count <= 0) {
    650650                                // destroy the map
    651                                 socket_port_map_destroy(&socket_port->map);
     651                                socket_port_map_destroy(&socket_port->map, free);
    652652                                // release the port
    653653                                socket_ports_exclude(global_sockets,
    654                                     socket->port);
     654                                    socket->port, free);
    655655                        } else {
    656656                                // remove
    657657                                socket_port_map_exclude(&socket_port->map,
    658                                     socket->key, socket->key_length);
     658                                    socket->key, socket->key_length, free);
    659659                        }
    660660                }
    661661        }
  • uspace/lib/net/tl/tl_common.c

    === modified file 'uspace/lib/net/tl/tl_common.c'
     
    181181                                packet_dimension->content = content;
    182182                        else
    183183                                packet_dimensions_exclude(packet_dimensions,
    184                                     DEVICE_INVALID_ID);
     184                                    DEVICE_INVALID_ID, free);
    185185                }
    186186        }
    187187
  • uspace/srv/net/il/arp/arp.c

    === modified file 'uspace/srv/net/il/arp/arp.c'
     
    156156                                free(proto->addr_data);
    157157                       
    158158                        arp_clear_addr(&proto->addresses);
    159                         arp_addr_destroy(&proto->addresses);
     159                        arp_addr_destroy(&proto->addresses, free);
    160160                }
    161161        }
    162162       
    163         arp_protos_clear(&device->protos);
     163        arp_protos_clear(&device->protos, free);
    164164}
    165165
    166166static int arp_clean_cache_req(int arp_phone)
     
    183183                }
    184184        }
    185185       
    186         arp_cache_clear(&arp_globals.cache);
     186        arp_cache_clear(&arp_globals.cache, free);
    187187        fibril_mutex_unlock(&arp_globals.lock);
    188188       
    189189        return EOK;
     
    211211        if (trans)
    212212                arp_clear_trans(trans);
    213213       
    214         arp_addr_exclude(&proto->addresses, address->value, address->length);
     214        arp_addr_exclude(&proto->addresses, address->value, address->length, free);
    215215       
    216216        fibril_mutex_unlock(&arp_globals.lock);
    217217        return EOK;
     
    344344                        rc = arp_addr_add(&proto->addresses, src_proto,
    345345                            header->protocol_length, trans);
    346346                        if (rc != EOK) {
    347                                 /* The generic char map has already freed trans! */
     347                                free(trans);
    348348                                return rc;
    349349                        }
    350350                }
     
    555555                index = arp_protos_add(&device->protos, proto->service, proto);
    556556                if (index < 0) {
    557557                        fibril_mutex_unlock(&arp_globals.lock);
    558                         arp_protos_destroy(&device->protos);
     558                        arp_protos_destroy(&device->protos, free);
    559559                        free(device);
    560560                        return index;
    561561                }
     
    568568                    arp_receiver);
    569569                if (device->phone < 0) {
    570570                        fibril_mutex_unlock(&arp_globals.lock);
    571                         arp_protos_destroy(&device->protos);
     571                        arp_protos_destroy(&device->protos, free);
    572572                        free(device);
    573573                        return EREFUSED;
    574574                }
     
    578578                    &device->packet_dimension);
    579579                if (rc != EOK) {
    580580                        fibril_mutex_unlock(&arp_globals.lock);
    581                         arp_protos_destroy(&device->protos);
     581                        arp_protos_destroy(&device->protos, free);
    582582                        free(device);
    583583                        return rc;
    584584                }
     
    588588                    &device->addr_data);
    589589                if (rc != EOK) {
    590590                        fibril_mutex_unlock(&arp_globals.lock);
    591                         arp_protos_destroy(&device->protos);
     591                        arp_protos_destroy(&device->protos, free);
    592592                        free(device);
    593593                        return rc;
    594594                }
     
    600600                        fibril_mutex_unlock(&arp_globals.lock);
    601601                        free(device->addr);
    602602                        free(device->addr_data);
    603                         arp_protos_destroy(&device->protos);
     603                        arp_protos_destroy(&device->protos, free);
    604604                        free(device);
    605605                        return rc;
    606606                }
     
    613613                        free(device->addr_data);
    614614                        free(device->broadcast_addr);
    615615                        free(device->broadcast_data);
    616                         arp_protos_destroy(&device->protos);
     616                        arp_protos_destroy(&device->protos, free);
    617617                        free(device);
    618618                        return rc;
    619619                }
     
    745745                         */
    746746                        arp_clear_trans(trans);
    747747                        arp_addr_exclude(&proto->addresses, target->value,
    748                             target->length);
     748                            target->length, free);
    749749                        return EAGAIN;
    750750                }
    751751               
     
    793793        rc = arp_addr_add(&proto->addresses, target->value, target->length,
    794794            trans);
    795795        if (rc != EOK) {
    796                 /* The generic char map has already freed trans! */
     796                free(trans);
    797797                return rc;
    798798        }
    799799       
     
    806806                 */
    807807                arp_clear_trans(trans);
    808808                arp_addr_exclude(&proto->addresses, target->value,
    809                     target->length);
     809                    target->length, free);
    810810                return ENOENT;
    811811        }
    812812       
  • uspace/srv/net/il/ip/ip.c

    === modified file 'uspace/srv/net/il/ip/ip.c'
     
    504504        rc = ip_netif_initialize(ip_netif);
    505505        if (rc != EOK) {
    506506                fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
    507                 ip_routes_destroy(&ip_netif->routes);
     507                ip_routes_destroy(&ip_netif->routes, free);
    508508                free(ip_netif);
    509509                return rc;
    510510        }
  • uspace/srv/net/net/net.c

    === modified file 'uspace/srv/net/net/net.c'
     
    554554                /* Read configuration files */
    555555                rc = read_netif_configuration(conf_files[i], netif);
    556556                if (rc != EOK) {
    557                         measured_strings_destroy(&netif->configuration);
     557                        measured_strings_destroy(&netif->configuration, free);
    558558                        free(netif);
    559559                        return rc;
    560560                }
     
    564564                    measured_strings_find(&netif->configuration, (uint8_t *) CONF_NAME, 0);
    565565                if (!setting) {
    566566                        fprintf(stderr, "%s: Network interface name is missing\n", NAME);
    567                         measured_strings_destroy(&netif->configuration);
     567                        measured_strings_destroy(&netif->configuration, free);
    568568                        free(netif);
    569569                        return EINVAL;
    570570                }
     
    573573                /* Add to the netifs map */
    574574                int index = netifs_add(&net_globals.netifs, netif->id, netif);
    575575                if (index < 0) {
    576                         measured_strings_destroy(&netif->configuration);
     576                        measured_strings_destroy(&netif->configuration, free);
    577577                        free(netif);
    578578                        return index;
    579579                }
     
    585585                rc = char_map_add(&net_globals.netif_names, netif->name, 0,
    586586                    index);
    587587                if (rc != EOK) {
    588                         measured_strings_destroy(&netif->configuration);
    589                         netifs_exclude_index(&net_globals.netifs, index);
     588                        measured_strings_destroy(&netif->configuration, free);
     589                        netifs_exclude_index(&net_globals.netifs, index, free);
    590590                        return rc;
    591591                }
    592592               
     
    594594                if (rc != EOK) {
    595595                        printf("%s: Ignoring failed interface %s (%s)\n", NAME,
    596596                            netif->name, str_error(rc));
    597                         measured_strings_destroy(&netif->configuration);
    598                         netifs_exclude_index(&net_globals.netifs, index);
     597                        measured_strings_destroy(&netif->configuration, free);
     598                        netifs_exclude_index(&net_globals.netifs, index, free);
    599599                        continue;
    600600                }
    601601               
  • uspace/srv/net/nil/eth/eth.c

    === modified file 'uspace/srv/net/nil/eth/eth.c'
     
    213213        rc = eth_protos_initialize(&eth_globals.protos);
    214214        if (rc != EOK) {
    215215                free(eth_globals.broadcast_addr);
    216                 eth_devices_destroy(&eth_globals.devices);
     216                eth_devices_destroy(&eth_globals.devices, free);
    217217        }
    218218out:
    219219        fibril_rwlock_write_unlock(&eth_globals.protos_lock);
  • uspace/srv/net/tl/tcp/tcp.c

    === modified file 'uspace/srv/net/tl/tcp/tcp.c'
     
    17061706                /* Unbind if bound */
    17071707                if (socket->port > 0) {
    17081708                        socket_ports_exclude(&tcp_globals.sockets,
    1709                             socket->port);
     1709                            socket->port, free);
    17101710                        socket->port = 0;
    17111711                }
    17121712        }
     
    24912491
    24922492        rc = packet_dimensions_initialize(&tcp_globals.dimensions);
    24932493        if (rc != EOK) {
    2494                 socket_ports_destroy(&tcp_globals.sockets);
     2494                socket_ports_destroy(&tcp_globals.sockets, free);
    24952495                goto out;
    24962496        }
    24972497
  • uspace/srv/net/tl/udp/udp.c

    === modified file 'uspace/srv/net/tl/udp/udp.c'
     
    416416       
    417417        rc = packet_dimensions_initialize(&udp_globals.dimensions);
    418418        if (rc != EOK) {
    419                 socket_ports_destroy(&udp_globals.sockets);
     419                socket_ports_destroy(&udp_globals.sockets, free);
    420420                fibril_rwlock_write_unlock(&udp_globals.lock);
    421421                return rc;
    422422        }
     
    433433        rc = net_get_conf_req(udp_globals.net_phone, &configuration, count,
    434434            &data);
    435435        if (rc != EOK) {
    436                 socket_ports_destroy(&udp_globals.sockets);
     436                socket_ports_destroy(&udp_globals.sockets, free);
    437437                fibril_rwlock_write_unlock(&udp_globals.lock);
    438438                return rc;
    439439        }