--- hal-0.4.2/hald/device_info.c.orig +++ hal-0.4.2/hald/device_info.c @@ -1,5 +1,5 @@ /*************************************************************************** - * CVSID: $Id: device_info.c,v 1.16.2.1 2004/11/22 21:53:50 david Exp $ + * CVSID: $Id: device_info.c,v 1.16.2.2 2005/03/28 19:15:19 david Exp $ * * device_store.c : Search for .fdi files and merge on match * @@ -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; }