看板 DFBSD_bugs 關於我們 聯絡資訊
This is a multi-part message in MIME format. --------------070204090507030605030301 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Timour Ezeev wrote: > I think you got small memory leak there IMHO (either tmp_cp is not used > but allocated or cp is lost). > > I think I see what you mean with the tmp_cp allocated but not used. I don't think I get you on the cp is lost part though. Is the attached better? Also, where would I put the free() exactly? I forgot about that.. -- Internet Explorer? Try FireFox at http://www.mozilla.org/products/firefox/ Outlook Express? Try ThunderBird at http://www.mozilla.org/products/thunderbird/ --------------070204090507030605030301 Content-Type: text/plain; name="hunt.c.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="hunt.c.diff" --- hunt.c.old 2004-10-27 16:44:06.000000000 +0100 +++ hunt.c 2004-10-27 17:40:20.000000000 +0100 @@ -58,17 +58,31 @@ hunt(name) char *name; { - register char *cp; + register char *cp, *tmp_cp; sig_t f; - int res; + int res, cp_len = 0; f = signal(SIGALRM, dead); while ((cp = getremote(name))) { deadfl = 0; - if ((uucplock = strrchr(cp, '/')) == NULL) - uucplock = cp; - else + + if ((uucplock = strrchr(cp, '/')) == NULL) { + cp_len = strlen(cp) + strlen("/dev/") + 1; + tmp_cp = malloc(sizeof(char) * cp_len); + + strncpy(tmp_cp, "/dev/", 6); + strncat(tmp_cp, cp, strlen(cp)); + + if ((uucplock = strrchr(tmp_cp, '/')) == NULL) { + uucplock = cp; + } else { + cp = tmp_cp; + ++uucplock; + } + } else { ++uucplock; + } + if ((res = uu_lock(uucplock)) != UU_LOCK_OK) { if (res != UU_LOCK_INUSE) fprintf(stderr, "uu_lock: %s\n", uu_lockerr(res)); --------------070204090507030605030301--