Skip to content

Commit

Permalink
test/reorder: fix freeing mbuf twice
Browse files Browse the repository at this point in the history
mbufs are being freed twice in error, once in rte_mempool_put_bulk()
and then in rte_reorder_free(). Refactor the code so that we use
rte_reorder_free() to free mbufs in the reorder buffer, and use
rte_pktmbuf_free() to free any unused or drained mbufs.

Fixes: d0c9b58 ("app/test: new reorder unit test")
Cc: stable@dpdk.org

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
Reviewed-by: David Hunt <david.hunt@intel.com>
  • Loading branch information
reshmapattan authored and tmonjalo committed May 13, 2018
1 parent c981825 commit ecd867f
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions test/test/test_reorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ test_reorder_insert(void)
b = rte_reorder_create("test_insert", rte_socket_id(), size);
TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");

ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");

for (i = 0; i < num_bufs; i++)
for (i = 0; i < num_bufs; i++) {
bufs[i] = rte_pktmbuf_alloc(p);
TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
bufs[i]->seqn = i;
}

/* This should fill up order buffer:
* reorder_seq = 0
Expand All @@ -165,6 +165,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
bufs[i] = NULL;
}

/* early packet - should move mbufs to ready buf and move sequence window
Expand All @@ -179,6 +180,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
bufs[4] = NULL;

/* early packet from current sequence window - full ready buffer */
bufs[5]->seqn = 2 * size;
Expand All @@ -189,6 +191,7 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
bufs[5] = NULL;

/* late packet */
bufs[6]->seqn = 3 * size;
Expand All @@ -199,11 +202,15 @@ test_reorder_insert(void)
ret = -1;
goto exit;
}
bufs[6] = NULL;

ret = 0;
exit:
rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
rte_reorder_free(b);
for (i = 0; i < num_bufs; i++) {
if (bufs[i] != NULL)
rte_pktmbuf_free(bufs[i]);
}
return ret;
}

Expand All @@ -219,6 +226,10 @@ test_reorder_drain(void)
int ret = 0;
unsigned i, cnt;

/* initialize all robufs to NULL */
for (i = 0; i < num_bufs; i++)
robufs[i] = NULL;

/* This would create a reorder buffer instance consisting of:
* reorder_seq = 0
* ready_buf: RB[size] = {NULL, NULL, NULL, NULL}
Expand All @@ -227,9 +238,6 @@ test_reorder_drain(void)
b = rte_reorder_create("test_drain", rte_socket_id(), size);
TEST_ASSERT_NOT_NULL(b, "Failed to create reorder buffer");

ret = rte_mempool_get_bulk(p, (void *)bufs, num_bufs);
TEST_ASSERT_SUCCESS(ret, "Error getting mbuf from pool");

/* Check no drained packets if reorder is empty */
cnt = rte_reorder_drain(b, robufs, 1);
if (cnt != 0) {
Expand All @@ -239,15 +247,19 @@ test_reorder_drain(void)
goto exit;
}

for (i = 0; i < num_bufs; i++)
for (i = 0; i < num_bufs; i++) {
bufs[i] = rte_pktmbuf_alloc(p);
TEST_ASSERT_NOT_NULL(bufs[i], "Packet allocation failed\n");
bufs[i]->seqn = i;
}

/* Insert packet with seqn 1:
* reorder_seq = 0
* RB[] = {NULL, NULL, NULL, NULL}
* OB[] = {1, NULL, NULL, NULL}
*/
rte_reorder_insert(b, bufs[1]);
bufs[1] = NULL;

cnt = rte_reorder_drain(b, robufs, 1);
if (cnt != 1) {
Expand All @@ -256,25 +268,31 @@ test_reorder_drain(void)
ret = -1;
goto exit;
}
if (robufs[0] != NULL)
rte_pktmbuf_free(robufs[i]);

/* Insert more packets
* RB[] = {NULL, NULL, NULL, NULL}
* OB[] = {NULL, 2, 3, NULL}
*/
rte_reorder_insert(b, bufs[2]);
rte_reorder_insert(b, bufs[3]);
bufs[2] = NULL;
bufs[3] = NULL;

/* Insert more packets
* RB[] = {NULL, NULL, NULL, NULL}
* OB[] = {NULL, 2, 3, 4}
*/
rte_reorder_insert(b, bufs[4]);
bufs[4] = NULL;

/* Insert more packets
* RB[] = {2, 3, 4, NULL}
* OB[] = {NULL, NULL, 7, NULL}
*/
rte_reorder_insert(b, bufs[7]);
bufs[7] = NULL;

/* drained expected packets */
cnt = rte_reorder_drain(b, robufs, 4);
Expand All @@ -284,6 +302,10 @@ test_reorder_drain(void)
ret = -1;
goto exit;
}
for (i = 0; i < 3; i++) {
if (robufs[i] != NULL)
rte_pktmbuf_free(robufs[i]);
}

/*
* RB[] = {NULL, NULL, NULL, NULL}
Expand All @@ -298,8 +320,13 @@ test_reorder_drain(void)
}
ret = 0;
exit:
rte_mempool_put_bulk(p, (void *)bufs, num_bufs);
rte_reorder_free(b);
for (i = 0; i < num_bufs; i++) {
if (bufs[i] != NULL)
rte_pktmbuf_free(bufs[i]);
if (robufs[i] != NULL)
rte_pktmbuf_free(robufs[i]);
}
return ret;
}

Expand Down

0 comments on commit ecd867f

Please sign in to comment.