JDK-4983832 : Memory leak on Windows when zip errors occur in zip_util.c:readLOC()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: generic
  • Submitted: 2004-01-27
  • Updated: 2004-02-06
  • Resolved: 2004-02-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b38Fixed
Related Reports
Relates :  
Description
By inspection, 

FREE_AND_RETURN_NULL:
#ifndef USE_MMAP
    if (ze != NULL) {
	if (ze->extra != NULL)
	    free(ze->extra);
	if (ze->name != NULL)
	    free(ze->name);
        free(ze);
    }
    if (locbuf != NULL)
        free(locbuf);
#endif

should be

 FREE_AND_RETURN_NULL:
    if (ze != NULL) {
	if (ze->extra != NULL)
	    free(ze->extra);
	if (ze->name != NULL)
	    free(ze->name);
        free(ze);
    }
#ifndef USE_MMAP
    if (locbuf != NULL)
        free(locbuf);
#endif

###@###.### 2004-01-26

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta2 FIXED IN: tiger-beta2 INTEGRATED IN: tiger-b38 tiger-beta2
14-06-2004

SUGGESTED FIX /u/martin/ws/zipleak2/webrev/src/share/native/java/util/zip/zip_util.c- 2004-01-26 20:30:57.517123000 -0800 +++ zip_util.c 2004-01-26 20:30:57.232538000 -0800 @@ -783,31 +783,25 @@ * The ZIP lock should be held here. */ static jzentry * readLOC(jzfile *zip, jzcell *zc) { - unsigned char *locbuf; jint nlen, elen; /* unsigned 16-bit */ jzentry *ze = NULL; jlong start, end; /* unsigned 32-bit */ #ifdef USE_MMAP - locbuf = zip->maddr + zc->pos; + unsigned char *locbuf = zip->maddr + zc->pos; #else + unsigned char locbuf[LOCHDR]; + /* Seek to beginning of LOC header */ if (JVM_Lseek(zip->fd, zc->pos, SEEK_SET) == -1) { zip->msg = "seek failed"; return NULL; } - /* Allocate buffer for LOC header only */ - locbuf = malloc(LOCHDR); - if (locbuf <= 0) { - zip->msg = "out of memory"; - return NULL; - } - /* Try to read in the LOC header */ if (readFully(zip->fd, locbuf, LOCHDR) == -1) { zip->msg = "couldn't read LOC header"; goto FREE_AND_RETURN_NULL; } @@ -941,27 +935,21 @@ ze->crc = zc->crc; /* Fill in the rest of the entry fields from the LOC */ ze->time = LOCTIM(locbuf); ze->pos = zc->pos + LOCHDR + LOCNAM(locbuf) + LOCEXT(locbuf); -#ifndef USE_MMAP - free(locbuf); -#endif + return ze; FREE_AND_RETURN_NULL: -#ifndef USE_MMAP if (ze != NULL) { if (ze->extra != NULL) free(ze->extra); if (ze->name != NULL) free(ze->name); free(ze); } - if (locbuf != NULL) - free(locbuf); -#endif return NULL; } /* * Free the given jzentry.
11-06-2004

PUBLIC COMMENTS -
10-06-2004

EVALUATION Agreed. ###@###.### 2004-01-26 There is a better fix than the one proposed by the submitter; one that is much more maintainable and slightly more efficient. See the Suggested Fix. ###@###.### 2004-01-28
28-01-2004