From 7049fbf759aa532316572a838dc9783e9d04fda5 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Fri, 26 Jul 2019 15:39:41 +0100 Subject: [PATCH] inspect-library: Make memory management more obvious We were relying on the fact that strsep(&line, ...) resets line to NULL when it reaches the end, which is not at all obvious. Swap the roles of the variables around. Signed-off-by: Simon McVittie <smcv@collabora.com> --- helpers/inspect-library.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/helpers/inspect-library.c b/helpers/inspect-library.c index 591de34fa..8418e210a 100644 --- a/helpers/inspect-library.c +++ b/helpers/inspect-library.c @@ -120,7 +120,6 @@ main (int argc, size_t missing_n = 0; size_t misversioned_n = 0; char *line = NULL; - char *r = NULL; size_t len = 0; ssize_t chars; bool first; @@ -198,13 +197,14 @@ main (int argc, /* Skip any empty line */ if (chars > 1) { - r = line; - symbol = strsep(&line, "@"); - version = strsep(&line, "@"); + char *pointer_into_line = line; + + symbol = strsep (&pointer_into_line, "@"); + version = strsep (&pointer_into_line, "@"); if (symbol == NULL) { fprintf (stderr, "Probably the symbol@version pair is mispelled."); - free (r); + free (line); free (missing_symbols); free (misversioned_symbols); clean_exit (handle); @@ -230,7 +230,9 @@ main (int argc, free (merged_string); } } - free (r); + free (line); + line = NULL; + len = 0; } } free (line); -- GitLab