static int doDescribeBundleTasks(struct nc_state_t *nc, ncMetadata * pMeta, char **instIds, int instIdsLen, bundleTask *** outBundleTasks, int *outBundleTasksLen)
{
    if (instIdsLen < 1 || instIds == NULL) {
        LOGDEBUG("internal error (invalid parameters to doDescribeBundleTasks)\n");
        return EUCA_ERROR;
    }
    // Maximum size
    *outBundleTasks = EUCA_ZALLOC(instIdsLen, sizeof(bundleTask *));
    if ((*outBundleTasks) == NULL) {
        return EUCA_MEMORY_ERROR;
    }

    *outBundleTasksLen = 0;            // we may return fewer than instIdsLen

    int i, j;
    for (i = 0, j = 0; i < instIdsLen; i++) {
        bundleTask *bundle = NULL;

        sem_p(inst_sem);
        ncInstance *instance = find_instance(&global_instances, instIds[i]);
        if (instance != NULL) {
            if ((bundle = allocate_bundleTask(instance)) == NULL) {
                LOGERROR("out of memory\n");
                sem_v(inst_sem);
                return EUCA_MEMORY_ERROR;
            }
        }
        sem_v(inst_sem);

        if (bundle) {
            (*outBundleTasks)[j++] = bundle;
            (*outBundleTasksLen)++;
        }
    }

    return EUCA_OK;
}
static int doDescribeBundleTasks(struct nc_state_t *nc, ncMetadata * pMeta, char **instIds, int instIdsLen, bundleTask *** outBundleTasks, int *outBundleTasksLen)
{
    if (instIdsLen < 1 || instIds == NULL) {
        LOGDEBUG("internal error (invalid parameters to doDescribeBundleTasks)\n");
        return EUCA_ERROR;
    }
     
    *outBundleTasks = EUCA_ZALLOC(instIdsLen, sizeof(bundleTask *));
    if ((*outBundleTasks) == NULL) {
        return EUCA_MEMORY_ERROR;
    }

    *outBundleTasksLen = 0;             

    int i, j;
    for (i = 0, j = 0; i < instIdsLen; i++) {
        bundleTask *bundle = NULL;

        sem_p(inst_sem);
        ncInstance *instance = find_instance(&global_instances, instIds[i]);
        if (instance != NULL) {
            if ((bundle = allocate_bundleTask(instance)) == NULL) {
                LOGERROR("out of memory\n");
                sem_v(inst_sem);
                return EUCA_MEMORY_ERROR;
            }
        }
        sem_v(inst_sem);

        if (bundle) {
            (*outBundleTasks)[j++] = bundle;
            (*outBundleTasksLen)++;
        }
    }

    return EUCA_OK;
}