]> granicus.if.org Git - graphviz/commitdiff
don't keep pointers to temporarily malloc'ed strings
authorellson <devnull@localhost>
Sun, 19 Jun 2005 12:01:45 +0000 (12:01 +0000)
committerellson <devnull@localhost>
Sun, 19 Jun 2005 12:01:45 +0000 (12:01 +0000)
lib/gvc/gvconfig.c
lib/gvc/gvplugin.c

index 5bf3ed0746c046743ab747df437a791cc8dc65e3..0d45b2f8e288405c893b12ad6894c8661e2c477e 100644 (file)
@@ -138,26 +138,14 @@ static char *token(int *nest, char **tokens)
 #ifndef DISABLE_LTDL
 static int gvconfig_plugin_install_from_config(GVC_t * gvc, char *s)
 {
-    char *p, *path, *packagename, *api, *type;
+    char *path, *packagename, *api, *type;
     api_t gv_api;
     int quality, rc;
     int nest = 0;
 
     separator(&nest, &s);
     while (*s) {
-       p = token(&nest, &s);
-       if (p[0] == '/') {
-           path = strdup(p);
-       } else {
-           path = malloc(strlen(libdir)
-                            + 1
-                            + strlen(p)
-                            + 1);
-           strcpy(path, libdir);
-           strcat(path, "/");
-           strcat(path, p);
-       }
-
+       path = token(&nest, &s);
        if (nest == 0)
            packagename = token(&nest, &s);
         else
@@ -167,7 +155,6 @@ static int gvconfig_plugin_install_from_config(GVC_t * gvc, char *s)
            gv_api = gvplugin_api(api);
            if (gv_api == -1) {
                agerr(AGERR, "invalid api in config: %s %s\n", path, api);
-               free(path);
                return 0;
            }
            do {
@@ -181,13 +168,11 @@ static int gvconfig_plugin_install_from_config(GVC_t * gvc, char *s)
                                    type, quality, packagename, path, NULL);
                    if (!rc) {
                        agerr(AGERR, "config error: %s %s %s\n", path, api, type);
-                       free(path);
                        return 0;
                    }
                }
            } while (nest == 2);
        } while (nest == 1);
-       free(path);
     }
     return 1;
 }
index 9b5bbb85c3e4eec4a0b4b0a71a36f6f5a125edcb..cf5ef9db79d486a6c9afe3ea73f76eec88cb404e 100644 (file)
@@ -31,6 +31,8 @@
 #include        "gvc.h"
 #include        "graph.h"
 
+static char *libdir = GVLIBDIR;
+
 /*
  * Define an apis array of name strings using an enumerated api_t as index.
  * The enumerated type is defined gvplugin.h.  The apis array is
@@ -103,23 +105,36 @@ gvplugin_library_t *gvplugin_library_load(char *path)
     lt_ptr ptr;
     char *s, *sym;
     int len;
+    static char *p;
 
     char *suffix = "_LTX_library";
 
+    p = realloc(p,strlen(libdir)
+                       + 1
+                       + strlen(path)
+                       + 1);
+    if (path[0] == '/') {
+       strcpy(p, path);
+    } else {
+       strcpy(p, libdir);
+       strcat(p, "/");
+       strcat(p, path);
+    }
+
     if (lt_dlinit()) {
         agerr(AGERR, "failed to init libltdl\n");
         return NULL;
     }
-    hndl = lt_dlopen (path);
+    hndl = lt_dlopen (p);
     if (!hndl) {
-        agerr(AGERR, "failed to dlopen %s\n", path);
+        agerr(AGERR, "failed to dlopen %s\n", p);
         return NULL;
     }
 
-    s = strrchr(path, '/');
+    s = strrchr(p, '/');
     len = strlen(s); 
-    if (len < strlen("libgvplugin_x")) {
-       agerr (AGERR,"invalid plugin path \"%s\"\n", path);
+    if (len < strlen("/libgvplugin_x")) {
+       agerr (AGERR,"invalid plugin path \"%s\"\n", p);
        return NULL;
     }
     sym = malloc(len + strlen(suffix) + 1);
@@ -129,7 +144,7 @@ gvplugin_library_t *gvplugin_library_load(char *path)
 
     ptr = lt_dlsym (hndl, sym);
     if (!ptr) {
-        agerr (AGERR,"failed to resolve %s in %s\n", sym, path);
+        agerr (AGERR,"failed to resolve %s in %s\n", sym, p);
        free(sym);
         return NULL;
     }