aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-10-15 21:23:52 +0200
committerChristian Grothoff <christian@grothoff.org>2017-10-15 21:23:52 +0200
commit3d4576cff6f27cb7e14b8481b95dafa966d279b0 (patch)
treedba1d51ee437cd1efe05ac3bccbfb4d5c73b4307
parente7ce6d724c1094db17e8241c83e50c77e5b4629f (diff)
downloadlibextractor-3d4576cff6f27cb7e14b8481b95dafa966d279b0.tar.gz
libextractor-3d4576cff6f27cb7e14b8481b95dafa966d279b0.zip
avoid calling free(NULL) on plugin load error
-rw-r--r--src/main/extractor_plugins.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/main/extractor_plugins.c b/src/main/extractor_plugins.c
index 24bb064..8dc53d2 100644
--- a/src/main/extractor_plugins.c
+++ b/src/main/extractor_plugins.c
@@ -50,7 +50,7 @@ get_symbol_with_prefix (void *lib_handle,
50 char *dot; 50 char *dot;
51 const char *(*opt_fun)(void); 51 const char *(*opt_fun)(void);
52 52
53 if (NULL != options) 53 if (NULL != options)
54 *options = NULL; 54 *options = NULL;
55 if (NULL == (sym_name = strrchr (prefix, '_'))) 55 if (NULL == (sym_name = strrchr (prefix, '_')))
56 return NULL; 56 return NULL;
@@ -72,7 +72,7 @@ get_symbol_with_prefix (void *lib_handle,
72 sym); 72 sym);
73 /* try without '_' first */ 73 /* try without '_' first */
74 symbol = lt_dlsym (lib_handle, name + 1); 74 symbol = lt_dlsym (lib_handle, name + 1);
75 if (NULL == symbol) 75 if (NULL == symbol)
76 { 76 {
77 /* now try with the '_' */ 77 /* now try with the '_' */
78 char *first_error = strdup (lt_dlerror ()); 78 char *first_error = strdup (lt_dlerror ());
@@ -100,9 +100,9 @@ get_symbol_with_prefix (void *lib_handle,
100 sym); 100 sym);
101 /* try without '_' first */ 101 /* try without '_' first */
102 opt_fun = lt_dlsym (lib_handle, name + 1); 102 opt_fun = lt_dlsym (lib_handle, name + 1);
103 if (NULL == opt_fun) 103 if (NULL == opt_fun)
104 opt_fun = lt_dlsym (lib_handle, name); 104 opt_fun = lt_dlsym (lib_handle, name);
105 if (NULL != opt_fun) 105 if (NULL != opt_fun)
106 *options = opt_fun (); 106 *options = opt_fun ();
107 } 107 }
108 free (sym); 108 free (sym);
@@ -143,7 +143,7 @@ EXTRACTOR_plugin_load_ (struct EXTRACTOR_PluginList *plugin)
143#if WINDOWS 143#if WINDOWS
144 wlibname[0] = L'\0'; 144 wlibname[0] = L'\0';
145 llibname[0] = '\0'; 145 llibname[0] = '\0';
146 if ( (MultiByteToWideChar (CP_UTF8, 0, plugin->libname, -1, 146 if ( (MultiByteToWideChar (CP_UTF8, 0, plugin->libname, -1,
147 wlibname, sizeof (wlibname)) <= 0) || 147 wlibname, sizeof (wlibname)) <= 0) ||
148 (WideCharToMultiByte (CP_ACP, 0, wlibname, -1, 148 (WideCharToMultiByte (CP_ACP, 0, wlibname, -1,
149 llibname, sizeof (llibname), NULL, NULL) < 0) ) 149 llibname, sizeof (llibname), NULL, NULL) < 0) )
@@ -159,7 +159,7 @@ EXTRACTOR_plugin_load_ (struct EXTRACTOR_PluginList *plugin)
159 plugin->libraryHandle = lt_dlopenadvise (llibname, 159 plugin->libraryHandle = lt_dlopenadvise (llibname,
160 advise); 160 advise);
161#else 161#else
162 plugin->libraryHandle = lt_dlopenadvise (plugin->libname, 162 plugin->libraryHandle = lt_dlopenadvise (plugin->libname,
163 advise); 163 advise);
164#endif 164#endif
165 lt_dladvise_destroy (&advise); 165 lt_dladvise_destroy (&advise);
@@ -178,7 +178,7 @@ EXTRACTOR_plugin_load_ (struct EXTRACTOR_PluginList *plugin)
178 "_EXTRACTOR_%s_extract_method", 178 "_EXTRACTOR_%s_extract_method",
179 plugin->libname, 179 plugin->libname,
180 &plugin->specials); 180 &plugin->specials);
181 if (NULL == plugin->extract_method) 181 if (NULL == plugin->extract_method)
182 { 182 {
183 LOG ("Resolving `extract' method of plugin `%s' failed: %s\n", 183 LOG ("Resolving `extract' method of plugin `%s' failed: %s\n",
184 plugin->short_libname, 184 plugin->short_libname,
@@ -286,17 +286,17 @@ EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev,
286 case '(': 286 case '(':
287 cpy[pos++] = '\0'; /* replace '(' by termination */ 287 cpy[pos++] = '\0'; /* replace '(' by termination */
288 lastconf = pos; /* start config from here, after (. */ 288 lastconf = pos; /* start config from here, after (. */
289 while ( ('\0' != cpy[pos]) && 289 while ( ('\0' != cpy[pos]) &&
290 (')' != cpy[pos])) 290 (')' != cpy[pos]))
291 pos++; /* config until ) or EOS. */ 291 pos++; /* config until ) or EOS. */
292 if (')' == cpy[pos]) 292 if (')' == cpy[pos])
293 { 293 {
294 cpy[pos++] = '\0'; /* write end of config here. */ 294 cpy[pos++] = '\0'; /* write end of config here. */
295 while ( (':' != cpy[pos]) && 295 while ( (':' != cpy[pos]) &&
296 ('\0' != cpy[pos]) ) 296 ('\0' != cpy[pos]) )
297 pos++; /* forward until real end of string found. */ 297 pos++; /* forward until real end of string found. */
298 cpy[pos++] = '\0'; 298 cpy[pos++] = '\0';
299 } 299 }
300 else 300 else
301 { 301 {
302 cpy[pos++] = '\0'; /* end of string. */ 302 cpy[pos++] = '\0'; /* end of string. */
@@ -313,13 +313,13 @@ EXTRACTOR_plugin_add_config (struct EXTRACTOR_PluginList *prev,
313 if ('-' == cpy[last]) 313 if ('-' == cpy[last])
314 { 314 {
315 last++; 315 last++;
316 prev = EXTRACTOR_plugin_remove (prev, 316 prev = EXTRACTOR_plugin_remove (prev,
317 &cpy[last]); 317 &cpy[last]);
318 } 318 }
319 else 319 else
320 { 320 {
321 prev = EXTRACTOR_plugin_add (prev, 321 prev = EXTRACTOR_plugin_add (prev,
322 &cpy[last], 322 &cpy[last],
323 (-1 != lastconf) ? &cpy[lastconf] : NULL, 323 (-1 != lastconf) ? &cpy[lastconf] : NULL,
324 flags); 324 flags);
325 } 325 }
@@ -346,7 +346,7 @@ EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev,
346 346
347 pos = prev; 347 pos = prev;
348 first = prev; 348 first = prev;
349 while ( (NULL != pos) && 349 while ( (NULL != pos) &&
350 (0 != strcmp (pos->short_libname, library)) ) 350 (0 != strcmp (pos->short_libname, library)) )
351 { 351 {
352 prev = pos; 352 prev = pos;
@@ -368,11 +368,11 @@ EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev,
368 if ( (NULL != pos->shm) && 368 if ( (NULL != pos->shm) &&
369 (0 == EXTRACTOR_IPC_shared_memory_change_rc_ (pos->shm, -1)) ) 369 (0 == EXTRACTOR_IPC_shared_memory_change_rc_ (pos->shm, -1)) )
370 EXTRACTOR_IPC_shared_memory_destroy_ (pos->shm); 370 EXTRACTOR_IPC_shared_memory_destroy_ (pos->shm);
371 free (pos->short_libname); 371 if (NULL != pos->libname)
372 free (pos->libname); 372 free (pos->libname);
373 free (pos->plugin_options); 373 free (pos->plugin_options);
374 if (NULL != pos->libraryHandle) 374 if (NULL != pos->libraryHandle)
375 lt_dlclose (pos->libraryHandle); 375 lt_dlclose (pos->libraryHandle);
376 free (pos); 376 free (pos);
377 return first; 377 return first;
378} 378}
@@ -383,7 +383,7 @@ EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList *prev,
383 * 383 *
384 * @param plugin the list of plugins 384 * @param plugin the list of plugins
385 */ 385 */
386void 386void
387EXTRACTOR_plugin_remove_all (struct EXTRACTOR_PluginList *plugins) 387EXTRACTOR_plugin_remove_all (struct EXTRACTOR_PluginList *plugins)
388{ 388{
389 while (NULL != plugins) 389 while (NULL != plugins)