[PATCH:libXaw 1/2] Correct order of arguments to XawStackFree()
Alan Coopersmith
alan.coopersmith at oracle.com
Sat May 26 15:17:48 PDT 2012
XawStackAlloc() & XawStackFree() are macros to automate the process of
using a fixed size stack buffer for strings smaller than the buffer size,
and allocating/freeing memory for larger strings.
XawStackFree is defined in src/Private.h as taking (pointer, stk_buffer)
and freeing pointer if it's not pointing to the stack buffer.
Most of the calls of this macro get the ordering right, but a couple
got it reversed, passing a stack buffer to free() instead of the
allocated pointer.
Found by the Parfait 0.5.0.1 bug checking tool:
Error: Free memory not allocated dynamically by alloc (CWE 590)
Free() was called on a pointer 'buf' to the auto variable 'buf'. Free() must only be used on dynamically allocated memory
at line 2281 of TextAction.c in function 'DoFormatText'.
'buf' allocated at line 0 as auto variable.
at line 2296 of TextAction.c in function 'DoFormatText'.
'buf' allocated at line 0 as auto variable.
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
src/TextAction.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/TextAction.c b/src/TextAction.c
index 6705316..fe7e573 100644
--- a/src/TextAction.c
+++ b/src/TextAction.c
@@ -2278,7 +2278,7 @@ DoFormatText(TextWidget ctx, XawTextPosition left, Bool force, int level,
text.length = bytes;
bytes -= text.length;
if (_XawTextReplace(ctx, tmp, tmp, &text)) {
- XawStackFree(buf, text.ptr);
+ XawStackFree(text.ptr, buf);
return (XawEditError);
}
if (num_pos) {
@@ -2293,7 +2293,7 @@ DoFormatText(TextWidget ctx, XawTextPosition left, Bool force, int level,
}
position += count;
right += count;
- XawStackFree(buf, text.ptr);
+ XawStackFree(text.ptr, buf);
}
break;
}
--
1.7.9.2
More information about the xorg-devel
mailing list