Skip to content

Commit

Permalink
Add tstring free test
Browse files Browse the repository at this point in the history
Commit cd179d3
("Ensure proper validation checks are done before freeing a tstring")
was supposed to have included a test.  Add it.

Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed Dec 8, 2021
1 parent 06b4c68 commit 269b70c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ dt_cg_tstring_xfree(dt_pcb_t *pcb, uint64_t offset)
}

assert(i < DT_TSTRING_SLOTS);
assert(ts->in_use != 0);

ts->in_use = 0;
}
Expand Down
29 changes: 29 additions & 0 deletions test/unittest/codegen/tst.tstring_free.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

/*
* Stress test some tstring-free cases.
*/

#pragma D option quiet

BEGIN {
trace(
(x = strjoin("abc", "def")) ==
(y = strjoin("abc", "def")) ? 0 : 1);
trace(strjoin(
(x = strjoin("abc", "def")),
(y = strjoin("ABC", "DEF"))));
trace(substr(
(x = strjoin("123", "456")),
2));
trace(x = strjoin("abc", "def"));
trace(x =
(y = strjoin("ABC", "DEF")));

exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/codegen/tst.tstring_free.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0abcdefABCDEF3456abcdefABCDEF

0 comments on commit 269b70c

Please sign in to comment.