gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r4310 - in GNUnet/src: applications/advertising application


From: grothoff
Subject: [GNUnet-SVN] r4310 - in GNUnet/src: applications/advertising applications/dht/module applications/dht/tools applications/fs/collection applications/fs/ecrs applications/fs/fsui applications/fs/lib applications/fs/module applications/fs/tools applications/gap applications/kvstore_sqlite applications/sqstore_mysql applications/sqstore_sqlite applications/tbench applications/topology_f2f applications/tracekit applications/transport server setup setup/gtk setup/lib setup/ncurses transports transports/upnp util/string
Date: Fri, 19 Jan 2007 14:14:43 -0800 (PST)

Author: grothoff
Date: 2007-01-19 14:14:29 -0800 (Fri, 19 Jan 2007)
New Revision: 4310

Modified:
   GNUnet/src/applications/advertising/advertising.c
   GNUnet/src/applications/dht/module/routing.c
   GNUnet/src/applications/dht/tools/dht_api.c
   GNUnet/src/applications/fs/collection/collection.c
   GNUnet/src/applications/fs/ecrs/namespace.c
   GNUnet/src/applications/fs/fsui/deserialize.c
   GNUnet/src/applications/fs/fsui/download.c
   GNUnet/src/applications/fs/fsui/search.c
   GNUnet/src/applications/fs/fsui/upload.c
   GNUnet/src/applications/fs/lib/fslib.c
   GNUnet/src/applications/fs/module/fs.c
   GNUnet/src/applications/fs/tools/gnunet-directory.c
   GNUnet/src/applications/gap/gap.c
   GNUnet/src/applications/kvstore_sqlite/kv_sqlite.c
   GNUnet/src/applications/sqstore_mysql/mysql.c
   GNUnet/src/applications/sqstore_sqlite/sqlite.c
   GNUnet/src/applications/tbench/tbench.c
   GNUnet/src/applications/topology_f2f/topology.c
   GNUnet/src/applications/tracekit/gnunet-tracekit.c
   GNUnet/src/applications/transport/transport.c
   GNUnet/src/server/core.c
   GNUnet/src/server/gnunet-transport-check.c
   GNUnet/src/server/gnunet-update.c
   GNUnet/src/server/handler.c
   GNUnet/src/setup/gnunet-setup.c
   GNUnet/src/setup/gtk/gconf.c
   GNUnet/src/setup/lib/tree.c
   GNUnet/src/setup/ncurses/mconf.c
   GNUnet/src/transports/tcp_old.c
   GNUnet/src/transports/upnp/util.c
   GNUnet/src/util/string/string.c
Log:
fixing various bugs (largely leaks on error paths and unchecked return values)

Modified: GNUnet/src/applications/advertising/advertising.c
===================================================================
--- GNUnet/src/applications/advertising/advertising.c   2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/advertising/advertising.c   2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -801,9 +801,10 @@
                        &ehelloHandler);
   capi->registerPlaintextHandler(p2p_PROTO_hello,
                                 &phelloHandler);
-  GC_attach_change_listener(capi->cfg,
-                           &configurationUpdateCallback,
-                           NULL);
+  if (0 != GC_attach_change_listener(capi->cfg,
+                                    &configurationUpdateCallback,
+                                    NULL)) 
+    GE_BREAK(capi->ectx, 0); 
   startBootstrap(capi);
   GE_ASSERT(capi->ectx,
            0 == GC_set_configuration_value_string(capi->cfg,

Modified: GNUnet/src/applications/dht/module/routing.c
===================================================================
--- GNUnet/src/applications/dht/module/routing.c        2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/dht/module/routing.c        2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -664,6 +664,8 @@
        done = YES;
        break;
       }
+      prev = pos;
+      pos = prev->next;
     }
     if (records[i]->sources == NULL) {
       FREE(records[i]->get);

Modified: GNUnet/src/applications/dht/tools/dht_api.c
===================================================================
--- GNUnet/src/applications/dht/tools/dht_api.c 2007-01-19 21:44:18 UTC (rev 
4309)
+++ GNUnet/src/applications/dht/tools/dht_api.c 2007-01-19 22:14:29 UTC (rev 
4310)
@@ -249,6 +249,7 @@
   ret = connection_write(sock,
                         &req->header);
   connection_destroy(sock);
+  FREE(req);
   return ret;
 }
 

Modified: GNUnet/src/applications/fs/collection/collection.c
===================================================================
--- GNUnet/src/applications/fs/collection/collection.c  2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/fs/collection/collection.c  2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -614,6 +614,7 @@
     MUTEX_UNLOCK(lock);
     return;
   }
+  FREE(dirData);
   CLOSE(fd);
   if (OK != ECRS_uploadFile(ectx,
                            cfg,

Modified: GNUnet/src/applications/fs/ecrs/namespace.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/namespace.c 2007-01-19 21:44:18 UTC (rev 
4309)
+++ GNUnet/src/applications/fs/ecrs/namespace.c 2007-01-19 22:14:29 UTC (rev 
4310)
@@ -461,6 +461,7 @@
     if (mdsize == -1) {
       GE_BREAK(ectx, 0);
       FREE(dstURI);
+      freePrivateKey(hk);
       return NULL;
     }
     size = sizeof(SBlock) + mdsize;

Modified: GNUnet/src/applications/fs/fsui/deserialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/deserialize.c       2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/fs/fsui/deserialize.c       2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -340,17 +340,15 @@
 
   /* deserialize collection data */
   READINT(big);
-  if (big == 0)
+  if (big == 0) {
+    ctx->collectionData = NULL;
     return OK;
+  }
   if ( (big > 16 * 1024 * 1024) ||
        (big < sizeof(unsigned int) ) ) {
     GE_BREAK(NULL, 0);
     return SYSERR;
   }
-  if (big == 0) {
-    ctx->collectionData = NULL;
-    return OK;
-  }
   ctx->collectionData
     = MALLOC(big);
   if (big - sizeof(unsigned int) !=

Modified: GNUnet/src/applications/fs/fsui/download.c
===================================================================
--- GNUnet/src/applications/fs/fsui/download.c  2007-01-19 21:44:18 UTC (rev 
4309)
+++ GNUnet/src/applications/fs/fsui/download.c  2007-01-19 22:14:29 UTC (rev 
4310)
@@ -462,9 +462,9 @@
   void * unused;
   int ret;
 
-  ectx = list->ctx->ectx;
   if (list == NULL)
     return NO;
+  ectx = list->ctx->ectx;
 
 #if DEBUG_DTM
   GE_LOG(ectx,

Modified: GNUnet/src/applications/fs/fsui/search.c
===================================================================
--- GNUnet/src/applications/fs/fsui/search.c    2007-01-19 21:44:18 UTC (rev 
4309)
+++ GNUnet/src/applications/fs/fsui/search.c    2007-01-19 22:14:29 UTC (rev 
4310)
@@ -352,7 +352,6 @@
                    "PTHREAD_CREATE");
     ECRS_freeUri(pos->uri);
     FREE(pos);
-    pos->state = FSUI_ERROR_JOINED;
     MUTEX_UNLOCK(ctx->lock);
     return NULL;
   }

Modified: GNUnet/src/applications/fs/fsui/upload.c
===================================================================
--- GNUnet/src/applications/fs/fsui/upload.c    2007-01-19 21:44:18 UTC (rev 
4309)
+++ GNUnet/src/applications/fs/fsui/upload.c    2007-01-19 22:14:29 UTC (rev 
4310)
@@ -157,6 +157,7 @@
     *error = STRDUP(GE_memory_get(mem, 0));
     GE_free_context(ee);
     GE_memory_free(mem);
+    FREE(data);
     return NULL;
   }
   GE_free_context(ee);

Modified: GNUnet/src/applications/fs/lib/fslib.c
===================================================================
--- GNUnet/src/applications/fs/lib/fslib.c      2007-01-19 21:44:18 UTC (rev 
4309)
+++ GNUnet/src/applications/fs/lib/fslib.c      2007-01-19 22:14:29 UTC (rev 
4310)
@@ -293,8 +293,12 @@
 #endif
   handle->req->header.type = htons(CS_PROTO_gap_QUERY_STOP);
   GE_ASSERT(NULL, ctx->sock != NULL);
-  connection_write(ctx->sock,
-                  &handle->req->header);
+  if (OK != connection_write(ctx->sock,
+                            &handle->req->header)) { 
+    GE_LOG(ctx->ectx,
+          GE_WARNING | GE_REQUEST | GE_DEVELOPER,
+          "FSLIB: failed to request stop search with gnunetd\n");
+  }
   MUTEX_LOCK(ctx->lock);
   for (i=ctx->handleCount-1;i>=0;i--)
     if (ctx->handles[i] == handle) {

Modified: GNUnet/src/applications/fs/module/fs.c
===================================================================
--- GNUnet/src/applications/fs/module/fs.c      2007-01-19 21:44:18 UTC (rev 
4309)
+++ GNUnet/src/applications/fs/module/fs.c      2007-01-19 22:14:29 UTC (rev 
4310)
@@ -171,6 +171,7 @@
                          &hc)) ||
        (! equalsHashCode512(&hc, query)) ) {
     GE_BREAK(ectx, 0); /* value failed verification! */
+    FREE(dv);
     return SYSERR;
   }
   if (YES != isDatumApplicable(ntohl(dv->type),

Modified: GNUnet/src/applications/fs/tools/gnunet-directory.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-directory.c 2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/fs/tools/gnunet-directory.c 2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -88,6 +88,7 @@
                             YES)) ||
        (len == 0) ) {
     printf(_("=\tError reading directory.\n"));
+    FREE(name);
     return;
   }
   md = NULL;

Modified: GNUnet/src/applications/gap/gap.c
===================================================================
--- GNUnet/src/applications/gap/gap.c   2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/applications/gap/gap.c   2007-01-19 22:14:29 UTC (rev 4310)
@@ -299,6 +299,8 @@
          rpos = rprev->next;
        continue;
       }
+      rprev = rpos;
+      rpos = rprev->next;
     }
     /* if we have no counts for a peer anymore,
        free pos entry */

Modified: GNUnet/src/applications/kvstore_sqlite/kv_sqlite.c
===================================================================
--- GNUnet/src/applications/kvstore_sqlite/kv_sqlite.c  2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/kvstore_sqlite/kv_sqlite.c  2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -577,13 +577,15 @@
 
   sprintf(del, "DELETE from %s where %s %s %s", kv->table, key_where, age ? 
"or" : "", age_where);
 
-  keyenc = MALLOC(keylen * 2);
-  keyenc_len = sqlite_encode_binary(key, keylen, keyenc);
 
   sq_prepare(dbh, del, &stmt);
   if (key) {
+    keyenc = MALLOC(keylen * 2);
+    keyenc_len = sqlite_encode_binary(key, keylen, keyenc);
     sqlite3_bind_blob(stmt, 1, keyenc, keyenc_len, SQLITE_STATIC);
     bind++;
+  } else {
+    keyenc = NULL;
   }
 
   if (age)
@@ -592,7 +594,7 @@
   if (sqlite3_step(stmt) != SQLITE_DONE)
   {
     FREE(del);
-    FREE(keyenc);
+    FREENONNULL(keyenc);
     LOG_SQLITE(dbh->dbh,
               LOG_ERROR, "delete");
     sqlite3_finalize(stmt);
@@ -601,7 +603,7 @@
   }
   sqlite3_finalize(stmt);
   FREE(del);
-  FREE(keyenc);
+  FREENONNULL(keyenc);
 
   return OK;
 }

Modified: GNUnet/src/applications/sqstore_mysql/mysql.c
===================================================================
--- GNUnet/src/applications/sqstore_mysql/mysql.c       2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/sqstore_mysql/mysql.c       2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -1369,9 +1369,12 @@
        GE_BREAK(ectx, mysql_num_fields(sql_res) == 1);
        content_size = 0;
       } else {
-       SSCANF(sql_row[0],
-              "%llu",
-              &content_size);
+       if (1 != SSCANF(sql_row[0],
+                       "%llu",
+                       &content_size)) {
+         GE_BREAK(ectx, 0);
+         content_size = 0;
+       }
       }
     }
     if (sql_res != NULL)

Modified: GNUnet/src/applications/sqstore_sqlite/sqlite.c
===================================================================
--- GNUnet/src/applications/sqstore_sqlite/sqlite.c     2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/sqstore_sqlite/sqlite.c     2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -213,9 +213,10 @@
                     "PRAGMA page_size=4092", NULL, NULL, ENULL));
 
   /* We have to do it here, because otherwise precompiling SQL might fail */
-  sq_prepare(ret->dbh,
-            "Select 1 from sqlite_master where tbl_name = 'gn070'",
-            &stmt);
+  CHECK(SQLITE_OK ==
+       sq_prepare(ret->dbh,
+                  "Select 1 from sqlite_master where tbl_name = 'gn070'",
+                  &stmt));
   if (sqlite3_step(stmt) == SQLITE_DONE) {
     if (sqlite3_exec(ret->dbh,
                     "CREATE TABLE gn070 ("

Modified: GNUnet/src/applications/tbench/tbench.c
===================================================================
--- GNUnet/src/applications/tbench/tbench.c     2007-01-19 21:44:18 UTC (rev 
4309)
+++ GNUnet/src/applications/tbench/tbench.c     2007-01-19 22:14:29 UTC (rev 
4310)
@@ -333,6 +333,7 @@
     postsem = NULL;
   }
   MUTEX_UNLOCK(lock);
+  FREE(p2p);
 #if DEBUG_TBENCH
   GE_LOG(ectx,
         GE_DEBUG | GE_BULK | GE_USER,

Modified: GNUnet/src/applications/topology_f2f/topology.c
===================================================================
--- GNUnet/src/applications/topology_f2f/topology.c     2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/topology_f2f/topology.c     2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -359,6 +359,7 @@
           _("Failed to read friends list from `%s'\n"),
           fn);
     FREE(fn);
+    FREE(data);
     return SYSERR;
   }
   FREE(fn);

Modified: GNUnet/src/applications/tracekit/gnunet-tracekit.c
===================================================================
--- GNUnet/src/applications/tracekit/gnunet-tracekit.c  2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/tracekit/gnunet-tracekit.c  2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -117,6 +117,7 @@
     SEMAPHORE_UP(doneSem);
     FREE(peersResponding);
     FREE(peersSeen);
+    FREE(buffer);
     return NULL;
   }
   if (format == 1)

Modified: GNUnet/src/applications/transport/transport.c
===================================================================
--- GNUnet/src/applications/transport/transport.c       2007-01-19 21:44:18 UTC 
(rev 4309)
+++ GNUnet/src/applications/transport/transport.c       2007-01-19 22:14:29 UTC 
(rev 4310)
@@ -428,6 +428,7 @@
     GE_LOG(ectx,
           GE_INFO | GE_USER | GE_REQUEST,
           _("No transport succeeded in creating a hello!\n"));
+    FREE(helos);
     return SYSERR;
   }
   used = 0;

Modified: GNUnet/src/server/core.c
===================================================================
--- GNUnet/src/server/core.c    2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/server/core.c    2007-01-19 22:14:29 UTC (rev 4310)
@@ -586,6 +586,7 @@
        FREE(pos);
        pos = nxt;
       } else {
+       prev = pos;
        pos = pos->next;
       }
     }

Modified: GNUnet/src/server/gnunet-transport-check.c
===================================================================
--- GNUnet/src/server/gnunet-transport-check.c  2007-01-19 21:44:18 UTC (rev 
4309)
+++ GNUnet/src/server/gnunet-transport-check.c  2007-01-19 22:14:29 UTC (rev 
4310)
@@ -139,7 +139,6 @@
                                              1,
                                              &repeat)) {
     *res = SYSERR;
-    FREE(helo);
     return;
   }
   total = repeat;

Modified: GNUnet/src/server/gnunet-update.c
===================================================================
--- GNUnet/src/server/gnunet-update.c   2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/server/gnunet-update.c   2007-01-19 22:14:29 UTC (rev 4310)
@@ -98,6 +98,7 @@
                                    "update_",
                                    NO);
   if (mptr == NULL) {
+    os_plugin_unload(library);
     FREE(name);
     return OK; /* module needs no updates! */
   }

Modified: GNUnet/src/server/handler.c
===================================================================
--- GNUnet/src/server/handler.c 2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/server/handler.c 2007-01-19 22:14:29 UTC (rev 4310)
@@ -363,6 +363,8 @@
     unsigned short plen;
     unsigned short ptyp;
 
+    FREENONNULL(copy);
+    copy = NULL;
     memcpy(&cpart,
           &msg[pos],
           sizeof(MESSAGE_HEADER));
@@ -430,6 +432,8 @@
                 "Handler aborted message processing after receiving message of 
type '%d'.\n",
                 ptyp);
 #endif
+         FREENONNULL(copy);
+         copy = NULL;
          return; /* handler says: do not process the rest of the message */
        }
        last++;
@@ -456,14 +460,16 @@
              "Handler aborted message processing after receiving message of 
type '%d'.\n",
              ptyp);
 #endif
+         FREENONNULL(copy);
+         copy = NULL;
          return; /* handler says: do not process the rest of the message */
        }
        last++;
       }
     } /* if plaintext */
-    FREENONNULL(copy);
-    copy = NULL;
   } /* while loop */
+  FREENONNULL(copy);
+  copy = NULL;
 }
 
 /**

Modified: GNUnet/src/setup/gnunet-setup.c
===================================================================
--- GNUnet/src/setup/gnunet-setup.c     2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/setup/gnunet-setup.c     2007-01-19 22:14:29 UTC (rev 4310)
@@ -113,8 +113,10 @@
   mptr = os_plugin_resolve_function(library,
                                    mainfunc,
                                    YES);
-  if (! mptr)
+  if (! mptr) {
+    os_plugin_unload(library);
     return SYSERR;
+  }
   mptr(argc,
        argv,
        library,

Modified: GNUnet/src/setup/gtk/gconf.c
===================================================================
--- GNUnet/src/setup/gtk/gconf.c        2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/setup/gtk/gconf.c        2007-01-19 22:14:29 UTC (rev 4310)
@@ -498,8 +498,16 @@
     gtk_widget_destroy(dialog);
     switch (ret) {
     case GTK_RESPONSE_YES:
-      GC_write_configuration(cfg,
-                            cfg_filename);
+      if (0 != GC_write_configuration(cfg,
+                                     cfg_filename)) {  
+       dialog = gtk_message_dialog_new(NULL,
+                                       GTK_DIALOG_MODAL,
+                                       GTK_MESSAGE_ERROR,
+                                       GTK_BUTTONS_OK,
+                                       _("Error saving configuration."));
+       gtk_dialog_run(GTK_DIALOG(dialog));
+       gtk_widget_destroy(dialog);
+      }
       return FALSE;
     case GTK_RESPONSE_NO:
       return FALSE;

Modified: GNUnet/src/setup/lib/tree.c
===================================================================
--- GNUnet/src/setup/lib/tree.c 2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/setup/lib/tree.c 2007-01-19 22:14:29 UTC (rev 4310)
@@ -170,6 +170,11 @@
   opt = scm_to_locale_string(option);
   sec = scm_to_locale_string(section);
   val = scm_is_true(yesno) ? 1 : 0;
+  if ( (opt == NULL) ||
+       (sec == NULL) ) {
+    GE_BREAK(NULL, 0);
+    return SCM_EOL;  
+  }
   t = tree_lookup(tc->root,
                  sec,
                  opt);
@@ -183,10 +188,8 @@
            opt,
            sec);
   }
-  if (sec != NULL)
-    free(sec);
-  if (opt != NULL)
-    free(opt);
+  free(sec);
+  free(opt);
   return SCM_EOL;
 }
 

Modified: GNUnet/src/setup/ncurses/mconf.c
===================================================================
--- GNUnet/src/setup/ncurses/mconf.c    2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/setup/ncurses/mconf.c    2007-01-19 22:14:29 UTC (rev 4310)
@@ -322,7 +322,6 @@
                                                     fitem.text)) {
            show_help(pos->option,
                      gettext_noop("Internal error! (Value invalid?)"));
-           FREE(fitem.text);
            break;
          }
          FREE(fitem.text);

Modified: GNUnet/src/transports/tcp_old.c
===================================================================
--- GNUnet/src/transports/tcp_old.c     2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/transports/tcp_old.c     2007-01-19 22:14:29 UTC (rev 4310)
@@ -581,9 +581,12 @@
     flags = MSG_DONTWAIT;
 #elif OSX
     {
-    int __tmp = 1;
-    if (setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE,
-        (void *)&__tmp, sizeof(__tmp)) < 0)
+    const int __tmp = 1;
+    if (setsockopt(s, 
+                  SOL_SOCKET,
+                  SO_NOSIGPIPE,
+                  (void *)&__tmp, 
+                  sizeof(__tmp)) != 0)
       GE_LOG_STRERROR(NULL,
                      GE_WARNING | GE_ADMIN | GE_BULK,
                      "setsockopt");
@@ -1159,11 +1162,14 @@
       tcp_shutdown = YES;
       return SYSERR;
     }
-    SETSOCKOPT(tcp_sock,
-              SOL_SOCKET,
-              SO_REUSEADDR,
-              &on,
-              sizeof(on));
+    if (0 != SETSOCKOPT(tcp_sock,
+                       SOL_SOCKET,
+                       SO_REUSEADDR,
+                       &on,
+                       sizeof(on))) 
+      GE_LOG_STRERROR(NULL,
+                     GE_WARNING | GE_ADMIN | GE_BULK,
+                     "setsockopt");
     memset((char *) &serverAddr,
           0,
           sizeof(serverAddr));

Modified: GNUnet/src/transports/upnp/util.c
===================================================================
--- GNUnet/src/transports/upnp/util.c   2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/transports/upnp/util.c   2007-01-19 22:14:29 UTC (rev 4310)
@@ -27,10 +27,12 @@
 
 /* Returns a NULL-terminated string after unescaping an entity
  * (eg. &amp;, &lt; &#38 etc.) starting at s. Returns NULL on failure.*/
-static const char *
-detect_entity(const char *text, int *length) {
+static char *
+detect_entity(const char *text, 
+             int *length) {
   const char *pln;
-  int len, pound;
+  int len;
+  int pound;
   
   if (!text || *text != '&')
     return NULL;
@@ -66,14 +68,15 @@
     pln = b;
     FREE(buf);
     len = 2;
-    while (isdigit((int) text[len])) len++;
-    if(text[len] == ';') len++;
+    while (isdigit((int) text[len]))
+      len++;
+    if (text[len] == ';') len++;
   } else
     return NULL;
   
   if (length)
     *length = len;
-  return pln;
+  return STRDUP(pln);
 }
 
 char * 
@@ -101,13 +104,14 @@
     char *app;
     while (*c) {
       int len;
-      const char *ent;
+      char *ent;
       
       if ((ent = detect_entity(c, &len)) != NULL) {
        app = g_strdup_printf("%s%s", ret, ent);
        FREE(ret);
        ret = app;
        c += len;
+       FREE(ent);
       } else if (!strncmp(c, "<br>", 4)) {
        app = g_strdup_printf("%s%s", ret, "\n");
        FREE(ret);

Modified: GNUnet/src/util/string/string.c
===================================================================
--- GNUnet/src/util/string/string.c     2007-01-19 21:44:18 UTC (rev 4309)
+++ GNUnet/src/util/string/string.c     2007-01-19 22:14:29 UTC (rev 4310)
@@ -298,24 +298,32 @@
     /* relative path */
     fil_ptr = fil;
     len = 512;
-    errno = ERANGE;
     fm = NULL;
-    while (errno == ERANGE) {
+    while (1) {
       buffer = MALLOC(len);
       if (getcwd(buffer, len) != NULL) {
        fm = buffer;
        break;
-      } else {
-       GE_LOG_STRERROR(ectx,
-                       GE_USER | GE_WARNING | GE_IMMEDIATE,
-                       "getcwd");
+      }
+      if ( (errno == ERANGE) &&
+          (len < 1024 * 1024 * 4) ) {
+       len *= 2;
        FREE(buffer);
-       buffer = getenv("PWD"); /* alternative */
-       if (buffer == NULL)
-         return NULL; /* fatal */
-       fm = STRDUP(buffer);
+       continue;
       }
+      FREE(buffer);
+      break;
     }
+    if (fm == NULL) {
+      GE_LOG_STRERROR(ectx,
+                     GE_USER | GE_WARNING | GE_IMMEDIATE,
+                     "getcwd");
+      buffer = getenv("PWD"); /* alternative */
+      if (buffer != NULL)
+       fm = STRDUP(buffer);
+    }
+    if (fm == NULL)
+      fm = STRDUP("./"); /* give up */
   }
   n = strlen(fm) + 1 + strlen(fil_ptr) + 1;
   buffer = MALLOC(n);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]