Changeset 15343


Ignore:
Timestamp:
04/22/12 01:11:46 (11 years ago)
Author:
nit
Message:

fix memleak

File:
1 edited

Legend:

Unmodified
Added
Removed
  • titan/titan/inetwork.h

    r15146 r15343  
    121121                node->device = device;
    122122        }
     123        else
     124                free(device);
    123125
    124126        if(ostrcmp(node->ip, ip) != 0)
     
    127129                node->ip = ip;
    128130        }
     131        else
     132                free(ip);
    129133
    130134        if(ostrcmp(node->netmask, netmask) != 0)
     
    133137                node->netmask = netmask;
    134138        }
     139        else
     140                free(netmask);
    135141
    136142        if(ostrcmp(node->broadcast, broadcast) != 0)
     
    139145                node->broadcast = broadcast;
    140146        }
     147        else
     148                free(broadcast);
    141149
    142150        if(flag == 0)
     
    147155                        node->mac = mac;
    148156                }
     157                else
     158                        free(mac);
    149159
    150160                node->dhcp = dhcp;
    151161        }
     162        else
     163                free(mac);
     164       
    152165        node->found = 1;
    153166
     
    346359                                tmp_mac = command(cmd);
    347360               
    348                                 if (tmp_mac != 0)
    349                                         tmp_mac = string_newline(ostrcat(tmp_mac, "", 1, 0));
     361                                if(tmp_mac != NULL)
     362                                        tmp_mac = string_newline(tmp_mac);
    350363                                else
    351364                                        tmp_mac = ostrcat(tmp_mac, "00:00:00:00:00:00", 1, 0);
     
    368381                {
    369382                        if(self == NULL)
    370                                 node = changeinetwork(tmp_device, tmp_ipaddresse, tmp_netmask, tmp_mac,  tmp_broadcast, tmp_dhcp, tmpinetwork, 0);
     383                                node = changeinetwork(tmp_device, tmp_ipaddresse, tmp_netmask, tmp_mac, tmp_broadcast, tmp_dhcp, tmpinetwork, 0);
    371384                        else
    372                                 node = changeinetwork(tmp_device, tmp_ipaddresse, tmp_netmask, tmp_mac,  tmp_broadcast, tmp_dhcp, tmpinetwork, 1);
    373                 }
    374                 else
    375                         node = addinetwork(tmp_device, tmp_ipaddresse, tmp_netmask, tmp_mac,  tmp_broadcast, tmp_dhcp, node);
     385                                node = changeinetwork(tmp_device, tmp_ipaddresse, tmp_netmask, tmp_mac, tmp_broadcast, tmp_dhcp, tmpinetwork, 1);
     386                }
     387                else
     388                        node = addinetwork(tmp_device, tmp_ipaddresse, tmp_netmask, tmp_mac, tmp_broadcast, tmp_dhcp, node);
    376389
    377390                free(cmd); cmd = NULL;
     
    384397        if(self == NULL)
    385398        {
     399                free(status.gateway); status.gateway = NULL;
    386400                tmp_gateway = getdefaultgw();
    387                 if (tmp_gateway != NULL)
     401                if(tmp_gateway != NULL)
    388402                {
    389403                        tmpstr = fixip(tmp_gateway, 0);
     
    394408
    395409                // DNSSERVER1
     410                free(status.dnsserver1); status.dnsserver1 = NULL;
    396411                cmd = ostrcat(cmd, "cat /var/etc/resolv.conf | grep nameserver | awk '{ print $2 }' | head -n1 | tail -n1", 1, 0);
    397412                tmp_dnsserver1 = ostrcat(tmp_dnsserver1 , command(cmd), 1, 1);
    398                 if (tmp_dnsserver1 != NULL)
     413                if(tmp_dnsserver1 != NULL)
    399414                {
    400415                        tmpstr = fixip(tmp_dnsserver1, 0);
     
    407422
    408423                // DNSSERVER2
     424                free(status.dnsserver2); status.dnsserver2 = NULL;
    409425                cmd = ostrcat(cmd, "cat /var/etc/resolv.conf | grep nameserver | awk '{ print $2 }' | head -n2 | tail -n1", 1, 0);
    410426                tmp_dnsserver2 = ostrcat(tmp_dnsserver2 , command(cmd), 1, 1);
    411                 if (tmp_dnsserver2 != NULL)
     427                if(tmp_dnsserver2 != NULL)
    412428                {
    413429                        tmpstr = fixip(tmp_dnsserver2, 0);
Note: See TracChangeset for help on using the changeset viewer.