enthought / enthought/Python-2.7.3

Suspicious memory leaks by reviewing the code

Đang mở
#3 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
3
Fork
12
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

It seems that when coming into the exception branch, perhaps memory leak will happen.

1.
```
static BOOL __stdcall
win32_wchdir(LPCWSTR path)
{
wchar_t _new_path[MAX_PATH+1], *new_path = _new_path;
int result;
wchar_t env[4] = L"=x:";

if(!SetCurrentDirectoryW(path))
return FALSE;
result = GetCurrentDirectoryW(MAX_PATH+1, new_path);
if (!result)
return FALSE;
if (result > MAX_PATH+1) {
new_path = malloc(result * sizeof(wchar_t));
if (!new_path) {
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
result = GetCurrentDirectoryW(result, new_path);
if (!result) {
free(new_path);
return FALSE;
}
}
if (wcsncmp(new_path, L"\\\\", 2) == 0 ||
wcsncmp(new_path, L"//", 2) == 0)
/* UNC path, nothing to do. */
return TRUE; ################### if new_path calls malloc, it nerver calls free
env[1] = new_path[0];
result = SetEnvironmentVariableW(env, new_path);
if (new_path != _new_path)
free(new_path);
return result;
}
```

2.
```
static PyObject *
posix_fdopen(PyObject *self, PyObject *args)
{
int fd;
char *orgmode = "r";
int bufsize = -1;
FILE *fp;
PyObject *f;
char *mode;
if (!PyArg_ParseTuple(args, "i|si", &fd, &orgmode, &bufsize))
return NULL;

/* Sanitize mode. See fileobject.c */
mode = PyMem_MALLOC(strlen(orgmode)+3);
if (!mode) {
PyErr_NoMemory();
return NULL;
}
strcpy(mode, orgmode);
if (_PyFile_SanitizeMode(mode)) {
PyMem_FREE(mode);
return NULL;
}
if (!_PyVerify_fd(fd))
return posix_error(); ################### mode nerver calls PyMem_FREE
Py_BEGIN_ALLOW_THREADS
#if !defined(MS_WINDOWS) && defined(HAVE_FCNTL_H)
if (mode[0] == 'a') {
/* try to make sure the O_APPEND flag is set */
int flags;
flags = fcntl(fd, F_GETFL);
if (flags != -1)
fcntl(fd, F_SETFL, flags | O_APPEND);
fp = fdopen(fd, mode);
if (fp == NULL && flags != -1)
/* restore old mode if fdopen failed */
fcntl(fd, F_SETFL, flags);
} else {
fp = fdopen(fd, mode);
}
#else
fp = fdopen(fd, mode);
#endif
Py_END_ALLOW_THREADS
PyMem_FREE(mode);
if (fp == NULL)
return posix_error();
/* The dummy filename used here must be kept in sync with the value
tested against in gzip.GzipFile.__init__() - see issue #13781. */
f = PyFile_FromFile(fp, "", orgmode, fclose);
if (f != NULL)
PyFile_SetBufSize(f, bufsize);
return f;
}
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.