libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 0b10d145926240dd86c1d70ff7f91258347a0d1c
parent f1445d85a8ade62fec54ddad1099b9ab5802cd37
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 12 Jun 2010 23:18:29 +0000

handle strange error better

Diffstat:
Msrc/main/extractor.c | 20++++++++++++++------
Msrc/plugins/png_extractor.c | 15+++++++++++----
2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/main/extractor.c b/src/main/extractor.c @@ -1398,14 +1398,15 @@ start_process (struct EXTRACTOR_PluginList *plugin) int p1[2]; int p2[2]; pid_t pid; + int status; + plugin->cpid = -1; #ifndef WINDOWS if (0 != pipe (p1)) #else if (0 != _pipe (p1, 0, _O_BINARY)) #endif { - plugin->cpid = -1; plugin->flags = EXTRACTOR_OPTION_DISABLED; return; } @@ -1417,7 +1418,6 @@ start_process (struct EXTRACTOR_PluginList *plugin) { close (p1[0]); close (p1[1]); - plugin->cpid = -1; plugin->flags = EXTRACTOR_OPTION_DISABLED; return; } @@ -1444,14 +1444,13 @@ start_process (struct EXTRACTOR_PluginList *plugin) close (p1[1]); close (p2[0]); close (p2[1]); - plugin->cpid = -1; plugin->flags = EXTRACTOR_OPTION_DISABLED; return; } if (pid == 0) { - close (p1[1]); - close (p2[0]); + close (p1[1]); + close (p2[0]); process_requests (plugin, p1[0], p2[1]); _exit (0); } @@ -1460,7 +1459,16 @@ start_process (struct EXTRACTOR_PluginList *plugin) close (p2[1]); plugin->cpipe_in = fdopen (p1[1], "w"); if (plugin->cpipe_in == NULL) - perror ("fdopen"); + { + perror ("fdopen"); + (void) kill (plugin->cpid, SIGKILL); + waitpid (plugin->cpid, &status, 0); + close (p1[0]); + close (p2[1]); + plugin->cpid = -1; + plugin->flags = EXTRACTOR_OPTION_DISABLED; + return; + } plugin->cpipe_out = p2[0]; } diff --git a/src/plugins/png_extractor.c b/src/plugins/png_extractor.c @@ -130,6 +130,7 @@ processiTXt (const char *data, int i; int compressed; char *buf; + char *lan; uLongf bufLen; int ret; int zret; @@ -143,15 +144,21 @@ processiTXt (const char *data, language = &data[pos]; ret = 0; if (stnlen (language, length - pos) > 0) - ADDF (EXTRACTOR_METATYPE_LANGUAGE, - stndup (language, length - pos)); + { + lan = stndup (language, length - pos); + ADDF (EXTRACTOR_METATYPE_LANGUAGE, + lan); + } pos += stnlen (language, length - pos) + 1; if (pos + 1 >= length) return 0; translated = &data[pos]; /* already in utf-8! */ if (stnlen (translated, length - pos) > 0) - ADDF (EXTRACTOR_METATYPE_KEYWORDS, - stndup (translated, length - pos)); + { + lan = stndup (translated, length - pos); + ADDF (EXTRACTOR_METATYPE_KEYWORDS, + lan); + } pos += stnlen (translated, length - pos) + 1; if (pos >= length) return 0;