]> granicus.if.org Git - strace/commitdiff
unwind.c: non-fatal handling of asprintf error
authorEugene Syromiatnikov <esyr@redhat.com>
Fri, 4 Aug 2017 06:43:16 +0000 (08:43 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 13 Dec 2017 00:35:31 +0000 (00:35 +0000)
An error returned by asprintf is a poor excuse for dying.

* unwind.c (asprintf_error_str): New string constant.
(sprint_call_or_error): Replace error_msg_and_die() with
perror_func_msg() and usage of asprintf_error_str for a return value.
(queue_print): Free tmp->output line only if it is not
asprintf_error_str.

unwind.c

index 703df779b20a9dafe4d50992970046d6d2e9751f..053561adef85c0589b2821a1e70f192f4dc32a2b 100644 (file)
--- a/unwind.c
+++ b/unwind.c
@@ -90,6 +90,8 @@ static void delete_mmap_cache(struct tcb *tcp, const char *caller);
 static unw_addr_space_t libunwind_as;
 static unsigned int mmap_cache_generation;
 
+static const char asprintf_error_str[] = "???";
+
 void
 unwind_init(void)
 {
@@ -454,8 +456,10 @@ sprint_call_or_error(const char *binary_filename,
        else
                n = asprintf(&output_line, STACK_ENTRY_BUG_FMT, __func__);
 
-       if (n < 0)
-               error_msg_and_die("error in asprintf");
+       if (n < 0) {
+               perror_func_msg("asprintf");
+               output_line = (char *) asprintf_error_str;
+       }
 
        return output_line;
 }
@@ -528,7 +532,9 @@ queue_print(struct queue_t *queue)
                tprints(tmp->output_line);
                line_ended();
 
-               free(tmp->output_line);
+               if (tmp->output_line != asprintf_error_str)
+                       free(tmp->output_line);
+
                tmp->output_line = NULL;
                tmp->next = NULL;
                free(tmp);