Index: /trunk/Nebulous/nebclient/src/nebclient.c
===================================================================
--- /trunk/Nebulous/nebclient/src/nebclient.c	(revision 4647)
+++ /trunk/Nebulous/nebclient/src/nebclient.c	(revision 4648)
@@ -4,5 +4,5 @@
  * Copyright (C) 2005  Joshua Hoblitt
  *
- * $Id: nebclient.c,v 1.30 2005-07-28 21:55:52 jhoblitt Exp $
+ * $Id: nebclient.c,v 1.31 2005-07-28 23:03:45 jhoblitt Exp $
  */
 
@@ -183,7 +183,12 @@
 {
     char            **locations;
-
-    if (nebFindInstances(server, key, NULL, &locations) < 2) {
+    int             instances;
+
+    instances = nebFindInstances(server, key, NULL, &locations);
+    if (instances < 2) {
         nebSetErr(server, "can not cull - not enough instances");
+        if (instances) {
+            nebFree(locations);
+        }
 
         return false;
@@ -262,5 +267,7 @@
     char            **loc;
 
-    // FIXME is this leaking memory when response goes out of scope?
+    // FIXME is this leaking memory when response goes out of scope?  the gsoap
+    // manual seems to 'suggest' that this is temporary data that gets cleaed
+    // up on the next soap function call
     if (soap_call_ns1__find_USCOREinstances(server->soap, server->endpoint,
             NULL, (char *)key, (char *)volume, &response) != SOAP_OK) {
@@ -270,15 +277,22 @@
 
     resultElements = response.result->__size;
-    resultArray    = response.result->__ptr;
-
-    loc = xmalloc(sizeof(char*) * resultElements);
-
-    for (i = 0; i < resultElements; i++) {
-        loc[i] = xmalloc(strlen(resultArray[i]) + 1);
-
-        strcpy(loc[i], resultArray[i]);
-    }
-
-    *locations = loc;
+
+    if (locations) {
+        if (resultElements) {
+            resultArray    = response.result->__ptr;
+
+            loc = xmalloc(sizeof(char*) * resultElements);
+
+            for (i = 0; i < resultElements; i++) {
+                loc[i] = xmalloc(strlen(resultArray[i]) + 1);
+
+                strcpy(loc[i], resultArray[i]);
+            }
+
+            *locations = loc;
+        } else {
+            *locations = NULL;
+        }
+    }
 
     return resultElements;
@@ -290,5 +304,5 @@
     char            *filename;
     
-    if (nebFindInstances(server, key, NULL, &locations) < 0) {
+    if (nebFindInstances(server, key, NULL, &locations) < 1) {
         nebSetErr(server, "no instances found");
 
@@ -324,4 +338,5 @@
     if (!nebParseURI(server, locations[0], &filename)) {
         nebSetErr(server, "can not parse URI");
+        nebFree(locations);
 
         return -1;
@@ -332,4 +347,5 @@
             nebSetErr(server, "write not allowed with multiple instances");
             nebFree(filename);
+            nebFree(locations);
 
             return -1;
@@ -344,7 +360,10 @@
     if (fh < 0) {
         nebSetErr(server, "open: %s", strerror(errno));
-
-        return -1;
-    }
+        nebFree(locations);
+
+        return -1;
+    }
+
+    nebFree(locations);
 
     return fh;
@@ -361,4 +380,5 @@
     if (n < 0) {
         nebSetErr(server, "no instances found");
+        nebFree(locations);
 
         return false;
@@ -467,5 +487,7 @@
     stat = xmalloc(sizeof(nebObjectStat));
 
-    // FIXME is this leaking memory when response goes out of scope?
+    // FIXME is this leaking memory when response goes out of scope?  the gsoap
+    // manual seems to 'suggest' that this is temporary data that gets cleaed
+    // up on the next soap function call
     if (soap_call_ns1__stat_USCOREobject(server->soap, server->endpoint,
             NULL, (char *)key, &response) != SOAP_OK) {
