aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavier.delcampo@orain.io>2020-03-25 10:48:54 +0100
committerXavier Del Campo Romero <xavier.delcampo@orain.io>2020-03-25 10:48:54 +0100
commit357d4f2c0fc52ae7e5967f542161d59d09830e27 (patch)
tree81da58b7f1bcc2f96222c76e982d1901b1610cc6
parent46d7c1715b9b710e5afc9a259f7d7c48ce7bcb01 (diff)
downloaddynstr-357d4f2c0fc52ae7e5967f542161d59d09830e27.tar.gz
Avoid free() if no string is present
-rw-r--r--dynstr.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/dynstr.c b/dynstr.c
index 025f1fc..f816155 100644
--- a/dynstr.c
+++ b/dynstr.c
@@ -89,6 +89,9 @@ enum dynstr_err dynstr_dup(struct dynstr *const dst, const struct dynstr *const
void dynstr_free(struct dynstr *const d)
{
- free(d->str);
- memset(d, 0, sizeof *d);
+ if (d->str)
+ {
+ free(d->str);
+ memset(d, 0, sizeof *d);
+ }
}