hal/hald device_info.c,1.16.2.1,1.16.2.2
David Zeuthen
david at freedesktop.org
Mon Mar 28 11:15:21 PST 2005
Update of /cvs/hal/hal/hald
In directory gabe:/tmp/cvs-serv26753/hald
Modified Files:
Tag: hal-0_4-stable-branch
device_info.c
Log Message:
2005-03-28 David Zeuthen <david at fubar.dk>
* hald/linux/osspec.c: Patch from Kay Sievers <kay.sievers at vrfy.org>
While playing around with hotplug event replay from initramfs, it
happens, that events are generated for devices HAL already knows
from its coldplug run. This leads to a lot of funny double entries
in the device store. :) We should prevent the device addition by
hotplug events if we already have one with the same sysfs-devpath.
* hald/device_info.c: Backport a memory leak fix from the new
development branch: Fix up error handling; remember to free the
XML_Parser context which fixes a 4.5MB memory leak on my system.
Verified by Timo Hoenig <thoenig at suse.de> to work.
Index: device_info.c
===================================================================
RCS file: /cvs/hal/hal/hald/device_info.c,v
retrieving revision 1.16.2.1
retrieving revision 1.16.2.2
diff -u -d -r1.16.2.1 -r1.16.2.2
--- device_info.c 22 Nov 2004 21:53:50 -0000 1.16.2.1
+++ device_info.c 28 Mar 2005 19:15:19 -0000 1.16.2.2
@@ -1026,15 +1026,22 @@
XML_Parser parser;
ParsingContext *parsing_context;
- snprintf (buf, 511, "%s/%s", dir, filename);
+ file = NULL;
+ filebuf = NULL;
+ parser = NULL;
+ parsing_context = NULL;
+
+ device_matched = FALSE;
+
+ snprintf (buf, sizeof (buf), "%s/%s", dir, filename);
/*HAL_INFO(("analysing file %s", buf)); */
/* open file and read it into a buffer; it's a small file... */
file = fopen (buf, "r");
if (file == NULL) {
- perror ("fopen");
- return FALSE;
+ HAL_ERROR (("Could not open file %s", buf));
+ goto out;
}
fseek (file, 0L, SEEK_END);
@@ -1042,25 +1049,27 @@
rewind (file);
filebuf = (char *) malloc (filesize);
if (filebuf == NULL) {
- perror ("malloc");
- fclose (file);
- return FALSE;
+ HAL_ERROR (("Could not allocate %d bytes for file %s", filesize, buf));
+ goto out;
}
fread (filebuf, sizeof (char), filesize, file);
-
- /* ok, now parse the file (should probably reuse parser and say we are
- * not thread safe
- */
- parser = XML_ParserCreate (NULL);
-
/* initialize parsing context */
parsing_context =
(ParsingContext *) malloc (sizeof (ParsingContext));
if (parsing_context == NULL) {
- perror ("malloc");
- return FALSE;
+ HAL_ERROR (("Could not allocate parsing context"));
+ goto out;
+ }
+
+ /* TODO: reuse parser
+ */
+ parser = XML_ParserCreate (NULL);
+ if (parser == NULL) {
+ HAL_ERROR (("Could not allocate XML parser"));
+ goto out;
}
+
parsing_context->depth = 0;
parsing_context->device_matched = FALSE;
parsing_context->match_ok = TRUE;
@@ -1095,9 +1104,15 @@
device_matched = parsing_context->device_matched;
}
- free (filebuf);
- fclose (file);
- free (parsing_context);
+out:
+ if (filebuf != NULL)
+ free (filebuf);
+ if (file != NULL)
+ fclose (file);
+ if (parser != NULL)
+ XML_ParserFree (parser);
+ if (parsing_context != NULL)
+ free (parsing_context);
return device_matched;
}
More information about the hal-commit
mailing list