Commit 6d095abe authored by Job Vranish's avatar Job Vranish
Browse files

Merge branch 'develop' of github.com:Seagate/kinetic-c into develop

parents 7afb26bf b43c9506
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -257,7 +257,7 @@ EXAMPLE_SRC = ./src/examples
EXAMPLE_LDFLAGS += -lm -l ssl $(KINETIC_LIB) -l crypto -l pthread
EXAMPLES = write_file_blocking
VALGRIND = valgrind
VALGRIND_ARGS = --leak-check=full
VALGRIND_ARGS = --track-origins=yes #--leak-check=full

example_sources = $(wildcard $(EXAMPLE_SRC)/*.c)
example_executables = $(patsubst $(EXAMPLE_SRC)/%.c,$(BIN_DIR)/examples/%,$(example_sources))
+2 −3
Original line number Diff line number Diff line
@@ -90,12 +90,11 @@ ByteBuffer ByteBuffer_CreateAndAppendFormattedCString(void* data, size_t max_len

    int formattedSize = vsnprintf((void*)tmpBuf.array.data, tmpBuf.array.len, format, args);
    assert(formattedSize >= 0);
    tmpBuf.bytesUsed = (tmpBuf.array.len <= (size_t)formattedSize) ? formattedSize : tmpBuf.array.len;
    tmpBuf.bytesUsed = (tmpBuf.array.len <= (size_t)formattedSize) ? tmpBuf.array.len : formattedSize;

    va_end(args);

    ByteBuffer_AppendBuffer(&buf, tmpBuf);

    return buf;
}

@@ -191,7 +190,7 @@ ByteBuffer* ByteBuffer_AppendFormattedCString(ByteBuffer* buffer, const char * f

    int formattedSize = vsnprintf((void*)tmpBuf.array.data, tmpBuf.array.len, format, args);
    assert(formattedSize >= 0);
    tmpBuf.bytesUsed = (tmpBuf.array.len <= (size_t)formattedSize) ? formattedSize : tmpBuf.array.len;
    tmpBuf.bytesUsed = (tmpBuf.array.len <= (size_t)formattedSize) ? tmpBuf.array.len : formattedSize;

    va_end(args);

+20 −7
Original line number Diff line number Diff line
@@ -110,14 +110,19 @@ static void* KineticAllocator_NewItem(KineticList* const list, size_t size)
    return newItem->data;
}

static void KineticAllocator_FreeItem(KineticList* const list, void* item)
static void KineticAllocator_FreeItem(KineticList* const list, void* item, bool lock)
{
    /* Make locking optional, since the lock may already be owned by the caller. */
    if (lock) {
        KINETIC_LIST_LOCK(list);
    }
    KineticListItem* cur = list->start;
    while (cur->data != item) {
        if (cur->next == NULL) {
            LOG1("  Reached end of list before finding item to free!");
            if (lock) {
                KINETIC_LIST_UNLOCK(list);
            }
            return;
        }
        else {
@@ -171,8 +176,10 @@ static void KineticAllocator_FreeItem(KineticList* const list, void* item)
        free(cur);
        cur = NULL;
    }
    if (lock) {
        KINETIC_LIST_UNLOCK(list);
    }
}

static void KineticAllocator_FreeList(KineticList* const list)
{
@@ -242,8 +249,14 @@ void KineticAllocator_FreePDU(KineticConnection* connection, KineticPDU* pdu)
        LOG3("Freeing dynamically allocated protobuf");
        KineticProto_Message__free_unpacked(pdu->proto, NULL);
    };
    
    /* TODO: We can't unlock until the function below completes, but it
     *     normally also tries to lock, so pass in a flag indicating
     *     we already have it locked. The way that the mutexes are
     *     currently initialized makes adding an attribute of
     *     PTHREAD_MUTEX_RECURSIVE significantly more trouble. */
    KineticAllocator_FreeItem(&connection->pdus, (void*)pdu, false);
    KINETIC_LIST_UNLOCK(&connection->pdus);
    KineticAllocator_FreeItem(&connection->pdus, (void*)pdu);
    LOGF3("Freed PDU (0x%0llX) on connection (0x%0llX)", pdu, connection);
}

@@ -320,7 +333,7 @@ void KineticAllocator_FreeOperation(KineticConnection* const connection, Kinetic
        KineticAllocator_FreePDU(connection, operation->response);
    }
    pthread_mutex_destroy(&operation->timeoutTimeMutex);
    KineticAllocator_FreeItem(&connection->operations, (void*)operation);
    KineticAllocator_FreeItem(&connection->operations, (void*)operation, true);
    LOGF3("Freed operation (0x%0llX) on connection (0x%0llX)", operation, connection);
}

@@ -360,7 +373,7 @@ void KineticAllocator_FreeAllOperations(KineticConnection* const connection)
                }

                current = current->next;
                KineticAllocator_FreeItem(&connection->operations, (void*)op);
                KineticAllocator_FreeItem(&connection->operations, (void*)op, true);
            }
        }
    }
+16 −0
Original line number Diff line number Diff line
@@ -141,6 +141,22 @@ KineticStatus ExecuteOperation(
        }
    }

    else if (strcmp("getnext", operation) == 0) {
        status = KineticClient_GetNext(sessionHandle, entry, NULL);
        if (status == 0) {
            printf("\nGetNext executed successfully."
                   "The entry has been retrieved!\n\n");
        }
    }

    else if (strcmp("getprevious", operation) == 0) {
        status = KineticClient_GetPrevious(sessionHandle, entry, NULL);
        if (status == 0) {
            printf("\nGetPrevious executed successfully."
                   "The entry has been retrieved!\n\n");
        }
    }

    else {
        printf("\nSpecified operation '%s' is invalid!\n\n", operation);
        return -1;
+5 −0
Original line number Diff line number Diff line
@@ -84,3 +84,8 @@ void SystemTestTearDown(SystemTestFixture* fixture)

    KineticClient_Shutdown();
}

bool SystemTestIsUnderSimulator(void)
{
    return 0 == strncmp(SYSTEM_TEST_HOST, "localhost", strlen("localhost"));
}
Loading