changeset 698:29d9083dff1c

Do not reallocate th_ioctx::mode string if it has not been allocated in the first place.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 10 Mar 2020 16:47:57 +0200
parents 87e97ea5afd1
children 3707a823aa02
files th_ioctx.c
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/th_ioctx.c	Mon Mar 09 22:26:19 2020 +0200
+++ b/th_ioctx.c	Tue Mar 10 16:47:57 2020 +0200
@@ -99,8 +99,15 @@
 
     thfclose(ctx);
 
-    if ((ctx->status = th_pstr_cpy(&ctx->mode, mode)) != THERR_OK)
-        return ctx->status;
+    if (ctx->mallocated)
+    {
+        if ((ctx->status = th_pstr_cpy(&ctx->mode, mode)) != THERR_OK)
+            return ctx->status;
+    }
+    else
+    {
+        ctx->mode = mode;
+    }
 
     return (ctx->status = thfopen(ctx));
 }