edg_wlpr_Log(LOG_DEBUG, "Trying to renew proxy in %s.%d",
                basename, record->suffix);
 
-   snprintf(tmp_proxy, sizeof(tmp_proxy), "%s.%d.renew.XXXXXX", 
+   snprintf(tmp_proxy, sizeof(tmp_proxy), "%s.%d.myproxy.XXXXXX", 
            basename, record->suffix);
    tmp_fd = mkstemp(tmp_proxy);
    if (tmp_fd == -1) {
       char tmp_voms_proxy[FILENAME_MAX];
       int tmp_voms_fd;
       
-      snprintf(tmp_voms_proxy, sizeof(tmp_voms_proxy), "%s.%d.renew.XXXXXX",
+      snprintf(tmp_voms_proxy, sizeof(tmp_voms_proxy), "%s.%d.voms.XXXXXX",
               basename, record->suffix);
       tmp_voms_fd = mkstemp(tmp_voms_proxy);
       if (tmp_voms_fd == -1) {
         goto end;
       }
 
-      ret = renew_voms_certs(repository_file, tmp_voms_proxy);
+      ret = renew_voms_creds(repository_file, renewed_proxy, tmp_voms_proxy);
+      close(tmp_voms_fd);
       if (ret) {
         unlink(tmp_voms_proxy);
         goto end;
       }
 
       renewed_proxy = tmp_voms_proxy;
+      unlink(tmp_proxy);
    }
 
    if (new_proxy)
 
 get_proxy_base_name(char *file, char **subject);
 
 int
-renew_voms_certs(const char *cur_file, const char *new_file);
+renew_voms_creds(const char *cur_file, const char *renewed_file, const char *new_file);
 
 #endif /* RENEWALD_LOCL_H */
 
    return 0;
 }
 
-int
-renew_voms_certs(const char *cur_file, const char *new_file)
+static int
+renew_voms_certs(const char *cur_file, const char *renewed_file, const char *new_file)
 {
    globus_gsi_cred_handle_t cur_proxy = NULL;
+   globus_gsi_cred_handle_t new_proxy = NULL;
    struct vomsdata *vd = NULL;
    struct voms **voms_cert = NULL;
    int voms_err, ret;
    if (ret)
       goto end;
 
-   ret = generate_proxy(cur_proxy, extension, new_file);
+   ret = load_proxy(renewed_file, NULL, NULL, NULL, &new_proxy);
+   if (ret)
+      goto end;
+
+   ret = generate_proxy(new_proxy, extension, new_file);
 
 end:
-#if 0
-   if (ret)
-      unlink(new_file);
-#endif
    (old_env_proxy) ? setenv("X509_USER_PROXY", old_env_proxy, 1) :
                     unsetenv("X509_USER_PROXY");
 
-   VOMS_Destroy(vd);
+   if (cert)
+      X509_free(cert);
+   if (chain)
+      sk_X509_pop_free(chain, X509_free);
+   if (vd)
+      VOMS_Destroy(vd);
+   if (cur_proxy)
+      globus_gsi_cred_handle_destroy(cur_proxy);
+   if (new_proxy)
+      globus_gsi_cred_handle_destroy(new_proxy);
+   if (buf)
+      free(buf);
 
    return ret;
 }
 
+int
+renew_voms_creds(const char *cur_file, const char *renewed_file, const char *new_file)
+{
+   return renew_voms_certs(cur_file, renewed_file, new_file);
+}
+
 #if 0
 int
 main(int argc, char *argv[])