From: Peter Verthez Date: Thu, 19 Sep 2002 06:23:29 +0000 (+0000) Subject: Clean up message buffer at exit. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=06992b01593e3a002319a2fb43ac16e6b73577ae;p=gedcom-parse.git Clean up message buffer at exit. --- diff --git a/gedcom/message.c b/gedcom/message.c index 738bcd0..213e049 100644 --- a/gedcom/message.c +++ b/gedcom/message.c @@ -41,6 +41,12 @@ void reset_mess_buffer() mess_buffer[0] = '\0'; } +void cleanup_mess_buffer() +{ + if (mess_buffer) + free(mess_buffer); +} + void init_mess_buffer() { if (mess_buffer == NULL) { @@ -48,6 +54,8 @@ void init_mess_buffer() if (mess_buffer) { mess_buffer[0] = '\0'; bufsize = INITIAL_BUF_SIZE; + if (atexit(cleanup_mess_buffer) != 0) + gedcom_warning(_("Could not register buffer cleanup function")); } else { fprintf(stderr, _("Could not allocate memory at %s, %d"), @@ -114,7 +122,10 @@ int gedcom_warning(const char* s, ...) va_list ap; reset_mess_buffer(); - safe_buf_append(_("Warning on line %d: "), line_no); + if (line_no != 0) + safe_buf_append(_("Warning on line %d: "), line_no); + else + safe_buf_append(_("Warning: ")); va_start(ap, s); res = safe_buf_vappend(s, ap); va_end(ap); @@ -130,7 +141,10 @@ int gedcom_error(const char* s, ...) va_list ap; reset_mess_buffer(); - safe_buf_append(_("Error on line %d: "), line_no); + if (line_no != 0) + safe_buf_append(_("Error on line %d: "), line_no); + else + safe_buf_append(_("Error: ")); va_start(ap, s); res = safe_buf_vappend(s, ap); va_end(ap);