[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] Fix openlog() ident usage



On Tue, Jan 20, 2009 at 08:36:27PM +0100, Daniel Veillard wrote:
> On Tue, Jan 20, 2009 at 11:14:03AM -0800, john levon sun com wrote:
> > It cannot be freed, as it's used by reference in the syslog code, at
> > least on Solaris.
> 
>   The requirement is apparently not present on Linux, sorry :-)
> 
>   I would prefer to keep the reference around and not leak it for
> example on reloads

  Another version with an extra strdup but making clearer what
the change do and fixing the closelog/free order,

 if tested positively please apply, thanks !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
Index: src/logging.c
===================================================================
RCS file: /data/cvs/libxen/src/logging.c,v
retrieving revision 1.6
diff -u -r1.6 logging.c
--- src/logging.c	15 Jan 2009 19:56:05 -0000	1.6
+++ src/logging.c	20 Jan 2009 21:15:20 -0000
@@ -626,15 +626,27 @@
     return(len);
 }
 
+static char *current_ident = NULL;
+
 static void virLogCloseSyslog(void *data ATTRIBUTE_UNUSED) {
     closelog();
+    VIR_FREE(current_ident);
 }
 
 static int virLogAddOutputToSyslog(int priority, const char *ident) {
-    openlog(ident, 0, 0);
+    /*
+     * ident need to be kept around on Solaris
+     */
+    VIR_FREE(current_ident);
+    current_ident = strdup(ident);
+    if (current_ident == NULL)
+        return(-1);
+
+    openlog(current_ident, 0, 0);
     if (virLogDefineOutput(virLogOutputToSyslog, virLogCloseSyslog, NULL,
                            priority, 0) < 0) {
         closelog();
+        VIR_FREE(current_ident);
         return(-1);
     }
     return(0);

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]