IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4648


Ignore:
Timestamp:
Jul 28, 2005, 1:03:45 PM (21 years ago)
Author:
jhoblitt
Message:

fix some memory leaks related to nebFindInstances()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/nebclient/src/nebclient.c

    r4646 r4648  
    44 * Copyright (C) 2005  Joshua Hoblitt
    55 *
    6  * $Id: nebclient.c,v 1.30 2005-07-28 21:55:52 jhoblitt Exp $
     6 * $Id: nebclient.c,v 1.31 2005-07-28 23:03:45 jhoblitt Exp $
    77 */
    88
     
    183183{
    184184    char            **locations;
    185 
    186     if (nebFindInstances(server, key, NULL, &locations) < 2) {
     185    int             instances;
     186
     187    instances = nebFindInstances(server, key, NULL, &locations);
     188    if (instances < 2) {
    187189        nebSetErr(server, "can not cull - not enough instances");
     190        if (instances) {
     191            nebFree(locations);
     192        }
    188193
    189194        return false;
     
    262267    char            **loc;
    263268
    264     // FIXME is this leaking memory when response goes out of scope?
     269    // FIXME is this leaking memory when response goes out of scope?  the gsoap
     270    // manual seems to 'suggest' that this is temporary data that gets cleaed
     271    // up on the next soap function call
    265272    if (soap_call_ns1__find_USCOREinstances(server->soap, server->endpoint,
    266273            NULL, (char *)key, (char *)volume, &response) != SOAP_OK) {
     
    270277
    271278    resultElements = response.result->__size;
    272     resultArray    = response.result->__ptr;
    273 
    274     loc = xmalloc(sizeof(char*) * resultElements);
    275 
    276     for (i = 0; i < resultElements; i++) {
    277         loc[i] = xmalloc(strlen(resultArray[i]) + 1);
    278 
    279         strcpy(loc[i], resultArray[i]);
    280     }
    281 
    282     *locations = loc;
     279
     280    if (locations) {
     281        if (resultElements) {
     282            resultArray    = response.result->__ptr;
     283
     284            loc = xmalloc(sizeof(char*) * resultElements);
     285
     286            for (i = 0; i < resultElements; i++) {
     287                loc[i] = xmalloc(strlen(resultArray[i]) + 1);
     288
     289                strcpy(loc[i], resultArray[i]);
     290            }
     291
     292            *locations = loc;
     293        } else {
     294            *locations = NULL;
     295        }
     296    }
    283297
    284298    return resultElements;
     
    290304    char            *filename;
    291305   
    292     if (nebFindInstances(server, key, NULL, &locations) < 0) {
     306    if (nebFindInstances(server, key, NULL, &locations) < 1) {
    293307        nebSetErr(server, "no instances found");
    294308
     
    324338    if (!nebParseURI(server, locations[0], &filename)) {
    325339        nebSetErr(server, "can not parse URI");
     340        nebFree(locations);
    326341
    327342        return -1;
     
    332347            nebSetErr(server, "write not allowed with multiple instances");
    333348            nebFree(filename);
     349            nebFree(locations);
    334350
    335351            return -1;
     
    344360    if (fh < 0) {
    345361        nebSetErr(server, "open: %s", strerror(errno));
    346 
    347         return -1;
    348     }
     362        nebFree(locations);
     363
     364        return -1;
     365    }
     366
     367    nebFree(locations);
    349368
    350369    return fh;
     
    361380    if (n < 0) {
    362381        nebSetErr(server, "no instances found");
     382        nebFree(locations);
    363383
    364384        return false;
     
    467487    stat = xmalloc(sizeof(nebObjectStat));
    468488
    469     // FIXME is this leaking memory when response goes out of scope?
     489    // FIXME is this leaking memory when response goes out of scope?  the gsoap
     490    // manual seems to 'suggest' that this is temporary data that gets cleaed
     491    // up on the next soap function call
    470492    if (soap_call_ns1__stat_USCOREobject(server->soap, server->endpoint,
    471493            NULL, (char *)key, &response) != SOAP_OK) {
Note: See TracChangeset for help on using the changeset viewer.