cu coredumps

Mark Cullen mark.cullen at dsl.pipex.com
Wed Oct 27 13:06:55 PDT 2004


Matthew Dillon wrote:
    (1) No you cannot safely use data that has been free()'d.  Not ever.  The
	original free() 15+ years ago had the side effect that the last
	free()'d data could still be used until the next free(), but nobody
	in their right mind programs to that spec any more.
    (2) No, you cannot assume that freed data will always cause a seg fault,
	or contain good or bad data. 

    (3) Stop worrying about performance for operations that are executed once
	and will take far less then 1 microsecond, and stop worrying about
	memory leaks for one-time string operations.  Don't worry about
	freeing the old data in this case.
    (4) Use asprintf().  Do not use malloc+str*() functions.  Especially do
	not use str*() functions for this sort of thing.  Just use asprintf().
						-Matt

Thank you for the asprintf() advice Matt. I am not sure if I used it 
right but it seems to work and it looks nicer.

How's this one then? Better? I hope so :)

--
Internet Explorer? Try FireFox at http://www.mozilla.org/products/firefox/
Outlook Express? Try ThunderBird at 
http://www.mozilla.org/products/thunderbird/
--- hunt.c.old	2004-10-27 16:44:06.000000000 +0100
+++ hunt.c	2004-10-27 21:05:14.000000000 +0100
@@ -36,6 +36,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <err.h>
 #include <libutil.h>
 #include "tipconf.h"
@@ -59,16 +60,37 @@
 	char *name;
 {
 	register char *cp;
+	char *tmp_cp;
 	sig_t f;
 	int res;
+	struct stat sb;
 
 	f = signal(SIGALRM, dead);
 	while ((cp = getremote(name))) {
 		deadfl = 0;
-		if ((uucplock = strrchr(cp, '/')) == NULL)
-			uucplock = cp;
-		else
-			++uucplock;
+
+		if (stat(cp, &sb) == 0) {
+			if ((uucplock = strrchr(cp, '/')) == NULL) {
+				uucplock = cp;		
+			} else {
+				++uucplock;
+			}
+		} else {
+			/* 
+			 * try to prefix with /dev/ if the cp doesn't 
+			 * have a /
+			 */
+			if ((uucplock = strrchr(cp, '/')) == NULL) {
+				if (asprintf(&tmp_cp, "%s%s", "/dev/", cp) > 0) {
+					cp = tmp_cp;
+				} else {
+					uucplock = cp;
+				}
+			} else {
+				uucplock = cp;
+			}
+		}
+
 		if ((res = uu_lock(uucplock)) != UU_LOCK_OK) {
 			if (res != UU_LOCK_INUSE)
 				fprintf(stderr, "uu_lock: %s\n", uu_lockerr(res));




More information about the Bugs mailing list