Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0df80697
Commit
0df80697
authored
Jul 22, 2006
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix more memory allocation issues found with failmalloc.
parent
aa79e9f7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
74 additions
and
36 deletions
+74
-36
Modules/bz2module.c
Modules/bz2module.c
+20
-8
Modules/cPickle.c
Modules/cPickle.c
+9
-4
Python/compile.c
Python/compile.c
+23
-13
Python/pyarena.c
Python/pyarena.c
+4
-4
Python/pythonrun.c
Python/pythonrun.c
+17
-6
Python/symtable.c
Python/symtable.c
+1
-1
No files found.
Modules/bz2module.c
View file @
0df80697
...
...
@@ -1348,8 +1348,10 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
#ifdef WITH_THREAD
self
->
lock
=
PyThread_allocate_lock
();
if
(
!
self
->
lock
)
if
(
!
self
->
lock
)
{
PyErr_SetString
(
PyExc_MemoryError
,
"unable to allocate lock"
);
goto
error
;
}
#endif
if
(
mode_char
==
'r'
)
...
...
@@ -1371,10 +1373,12 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
return
0
;
error:
Py_
DECREF
(
self
->
file
);
Py_
CLEAR
(
self
->
file
);
#ifdef WITH_THREAD
if
(
self
->
lock
)
if
(
self
->
lock
)
{
PyThread_free_lock
(
self
->
lock
);
self
->
lock
=
NULL
;
}
#endif
return
-
1
;
}
...
...
@@ -1682,8 +1686,10 @@ BZ2Comp_init(BZ2CompObject *self, PyObject *args, PyObject *kwargs)
#ifdef WITH_THREAD
self
->
lock
=
PyThread_allocate_lock
();
if
(
!
self
->
lock
)
if
(
!
self
->
lock
)
{
PyErr_SetString
(
PyExc_MemoryError
,
"unable to allocate lock"
);
goto
error
;
}
#endif
memset
(
&
self
->
bzs
,
0
,
sizeof
(
bz_stream
));
...
...
@@ -1698,8 +1704,10 @@ BZ2Comp_init(BZ2CompObject *self, PyObject *args, PyObject *kwargs)
return
0
;
error:
#ifdef WITH_THREAD
if
(
self
->
lock
)
if
(
self
->
lock
)
{
PyThread_free_lock
(
self
->
lock
);
self
->
lock
=
NULL
;
}
#endif
return
-
1
;
}
...
...
@@ -1894,8 +1902,10 @@ BZ2Decomp_init(BZ2DecompObject *self, PyObject *args, PyObject *kwargs)
#ifdef WITH_THREAD
self
->
lock
=
PyThread_allocate_lock
();
if
(
!
self
->
lock
)
if
(
!
self
->
lock
)
{
PyErr_SetString
(
PyExc_MemoryError
,
"unable to allocate lock"
);
goto
error
;
}
#endif
self
->
unused_data
=
PyString_FromString
(
""
);
...
...
@@ -1915,10 +1925,12 @@ BZ2Decomp_init(BZ2DecompObject *self, PyObject *args, PyObject *kwargs)
error:
#ifdef WITH_THREAD
if
(
self
->
lock
)
if
(
self
->
lock
)
{
PyThread_free_lock
(
self
->
lock
);
self
->
lock
=
NULL
;
}
#endif
Py_
XDECREF
(
self
->
unused_data
);
Py_
CLEAR
(
self
->
unused_data
);
return
-
1
;
}
...
...
Modules/cPickle.c
View file @
0df80697
...
...
@@ -196,7 +196,7 @@ Pdata_clear(Pdata *self, int clearto)
for
(
i
=
self
->
length
,
p
=
self
->
data
+
clearto
;
--
i
>=
clearto
;
p
++
)
{
Py_
DECREF
(
*
p
);
Py_
CLEAR
(
*
p
);
}
self
->
length
=
clearto
;
...
...
@@ -208,6 +208,7 @@ Pdata_grow(Pdata *self)
{
int
bigger
;
size_t
nbytes
;
PyObject
**
tmp
;
bigger
=
self
->
size
<<
1
;
if
(
bigger
<=
0
)
/* was 0, or new value overflows */
...
...
@@ -217,14 +218,14 @@ Pdata_grow(Pdata *self)
nbytes
=
(
size_t
)
bigger
*
sizeof
(
PyObject
*
);
if
(
nbytes
/
sizeof
(
PyObject
*
)
!=
(
size_t
)
bigger
)
goto
nomemory
;
self
->
data
=
realloc
(
self
->
data
,
nbytes
);
if
(
self
->
data
==
NULL
)
tmp
=
realloc
(
self
->
data
,
nbytes
);
if
(
tmp
==
NULL
)
goto
nomemory
;
self
->
data
=
tmp
;
self
->
size
=
bigger
;
return
0
;
nomemory:
self
->
size
=
0
;
PyErr_NoMemory
();
return
-
1
;
}
...
...
@@ -4163,6 +4164,7 @@ do_append(Unpicklerobject *self, int x)
int
list_len
;
slice
=
Pdata_popList
(
self
->
stack
,
x
);
if
(
!
slice
)
return
-
1
;
list_len
=
PyList_GET_SIZE
(
list
);
i
=
PyList_SetSlice
(
list
,
list_len
,
list_len
,
slice
);
Py_DECREF
(
slice
);
...
...
@@ -5167,6 +5169,9 @@ newUnpicklerobject(PyObject *f)
if
(
!
(
self
->
memo
=
PyDict_New
()))
goto
err
;
if
(
!
self
->
stack
)
goto
err
;
Py_INCREF
(
f
);
self
->
file
=
f
;
...
...
Python/compile.c
View file @
0df80697
...
...
@@ -300,8 +300,11 @@ PyCodeObject *
PyNode_Compile
(
struct
_node
*
n
,
const
char
*
filename
)
{
PyCodeObject
*
co
=
NULL
;
mod_ty
mod
;
PyArena
*
arena
=
PyArena_New
();
mod_ty
mod
=
PyAST_FromNode
(
n
,
NULL
,
filename
,
arena
);
if
(
!
arena
)
return
NULL
;
mod
=
PyAST_FromNode
(
n
,
NULL
,
filename
,
arena
);
if
(
mod
)
co
=
PyAST_Compile
(
mod
,
filename
,
NULL
,
arena
);
PyArena_Free
(
arena
);
...
...
@@ -615,8 +618,10 @@ markblocks(unsigned char *code, int len)
unsigned
int
*
blocks
=
(
unsigned
int
*
)
PyMem_Malloc
(
len
*
sizeof
(
int
));
int
i
,
j
,
opcode
,
blockcnt
=
0
;
if
(
blocks
==
NULL
)
if
(
blocks
==
NULL
)
{
PyErr_NoMemory
();
return
NULL
;
}
memset
(
blocks
,
0
,
len
*
sizeof
(
int
));
/* Mark labels in the first pass */
...
...
@@ -1071,14 +1076,14 @@ compiler_unit_free(struct compiler_unit *u)
PyObject_Free
((
void
*
)
b
);
b
=
next
;
}
Py_
XDECREF
(
u
->
u_ste
);
Py_
XDECREF
(
u
->
u_name
);
Py_
XDECREF
(
u
->
u_consts
);
Py_
XDECREF
(
u
->
u_names
);
Py_
XDECREF
(
u
->
u_varnames
);
Py_
XDECREF
(
u
->
u_freevars
);
Py_
XDECREF
(
u
->
u_cellvars
);
Py_
XDECREF
(
u
->
u_private
);
Py_
CLEAR
(
u
->
u_ste
);
Py_
CLEAR
(
u
->
u_name
);
Py_
CLEAR
(
u
->
u_consts
);
Py_
CLEAR
(
u
->
u_names
);
Py_
CLEAR
(
u
->
u_varnames
);
Py_
CLEAR
(
u
->
u_freevars
);
Py_
CLEAR
(
u
->
u_cellvars
);
Py_
CLEAR
(
u
->
u_private
);
PyObject_Free
(
u
);
}
...
...
@@ -1139,7 +1144,8 @@ compiler_enter_scope(struct compiler *c, identifier name, void *key,
/* Push the old compiler_unit on the stack. */
if
(
c
->
u
)
{
PyObject
*
wrapper
=
PyCObject_FromVoidPtr
(
c
->
u
,
NULL
);
if
(
PyList_Append
(
c
->
c_stack
,
wrapper
)
<
0
)
{
if
(
!
wrapper
||
PyList_Append
(
c
->
c_stack
,
wrapper
)
<
0
)
{
Py_XDECREF
(
wrapper
);
compiler_unit_free
(
u
);
return
0
;
}
...
...
@@ -1265,6 +1271,7 @@ compiler_next_instr(struct compiler *c, basicblock *b)
sizeof
(
struct
instr
)
*
DEFAULT_BLOCK_SIZE
);
}
else
if
(
b
->
b_iused
==
b
->
b_ialloc
)
{
struct
instr
*
tmp
;
size_t
oldsize
,
newsize
;
oldsize
=
b
->
b_ialloc
*
sizeof
(
struct
instr
);
newsize
=
oldsize
<<
1
;
...
...
@@ -1273,10 +1280,13 @@ compiler_next_instr(struct compiler *c, basicblock *b)
return
-
1
;
}
b
->
b_ialloc
<<=
1
;
b
->
b_instr
=
(
struct
instr
*
)
PyObject_Realloc
(
tmp
=
(
struct
instr
*
)
PyObject_Realloc
(
(
void
*
)
b
->
b_instr
,
newsize
);
if
(
b
->
b_instr
==
NULL
)
if
(
tmp
==
NULL
)
{
PyErr_NoMemory
();
return
-
1
;
}
b
->
b_instr
=
tmp
;
memset
((
char
*
)
b
->
b_instr
+
oldsize
,
0
,
newsize
-
oldsize
);
}
return
b
->
b_iused
++
;
...
...
Python/pyarena.c
View file @
0df80697
...
...
@@ -132,19 +132,19 @@ PyArena_New()
{
PyArena
*
arena
=
(
PyArena
*
)
malloc
(
sizeof
(
PyArena
));
if
(
!
arena
)
return
NULL
;
return
(
PyArena
*
)
PyErr_NoMemory
()
;
arena
->
a_head
=
block_new
(
DEFAULT_BLOCK_SIZE
);
arena
->
a_cur
=
arena
->
a_head
;
if
(
!
arena
->
a_head
)
{
free
((
void
*
)
arena
);
return
NULL
;
return
(
PyArena
*
)
PyErr_NoMemory
()
;
}
arena
->
a_objects
=
PyList_New
(
0
);
if
(
!
arena
->
a_objects
)
{
block_free
(
arena
->
a_head
);
free
((
void
*
)
arena
);
return
NULL
;
return
(
PyArena
*
)
PyErr_NoMemory
()
;
}
#if defined(Py_DEBUG)
arena
->
total_allocs
=
0
;
...
...
@@ -191,7 +191,7 @@ PyArena_Malloc(PyArena *arena, size_t size)
{
void
*
p
=
block_alloc
(
arena
->
a_cur
,
size
);
if
(
!
p
)
return
NULL
;
return
PyErr_NoMemory
()
;
#if defined(Py_DEBUG)
arena
->
total_allocs
++
;
arena
->
total_size
+=
size
;
...
...
Python/pythonrun.c
View file @
0df80697
...
...
@@ -746,6 +746,11 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
ps2
=
PyString_AsString
(
w
);
}
arena
=
PyArena_New
();
if
(
arena
==
NULL
)
{
Py_XDECREF
(
v
);
Py_XDECREF
(
w
);
return
-
1
;
}
mod
=
PyParser_ASTFromFile
(
fp
,
filename
,
Py_single_input
,
ps1
,
ps2
,
flags
,
&
errcode
,
arena
);
...
...
@@ -1203,9 +1208,8 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
PyObject
*
locals
,
PyCompilerFlags
*
flags
)
{
PyObject
*
ret
=
NULL
;
PyArena
*
arena
=
PyArena_New
();
mod_ty
mod
;
PyArena
*
arena
=
PyArena_New
();
if
(
arena
==
NULL
)
return
NULL
;
...
...
@@ -1221,9 +1225,8 @@ PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,
PyObject
*
locals
,
int
closeit
,
PyCompilerFlags
*
flags
)
{
PyObject
*
ret
;
PyArena
*
arena
=
PyArena_New
();
mod_ty
mod
;
PyArena
*
arena
=
PyArena_New
();
if
(
arena
==
NULL
)
return
NULL
;
...
...
@@ -1291,8 +1294,12 @@ Py_CompileStringFlags(const char *str, const char *filename, int start,
PyCompilerFlags
*
flags
)
{
PyCodeObject
*
co
;
mod_ty
mod
;
PyArena
*
arena
=
PyArena_New
();
mod_ty
mod
=
PyParser_ASTFromString
(
str
,
filename
,
start
,
flags
,
arena
);
if
(
arena
==
NULL
)
return
NULL
;
mod
=
PyParser_ASTFromString
(
str
,
filename
,
start
,
flags
,
arena
);
if
(
mod
==
NULL
)
{
PyArena_Free
(
arena
);
return
NULL
;
...
...
@@ -1311,8 +1318,12 @@ struct symtable *
Py_SymtableString
(
const
char
*
str
,
const
char
*
filename
,
int
start
)
{
struct
symtable
*
st
;
mod_ty
mod
;
PyArena
*
arena
=
PyArena_New
();
mod_ty
mod
=
PyParser_ASTFromString
(
str
,
filename
,
start
,
NULL
,
arena
);
if
(
arena
==
NULL
)
return
NULL
;
mod
=
PyParser_ASTFromString
(
str
,
filename
,
start
,
NULL
,
arena
);
if
(
mod
==
NULL
)
{
PyArena_Free
(
arena
);
return
NULL
;
...
...
Python/symtable.c
View file @
0df80697
...
...
@@ -727,7 +727,7 @@ symtable_exit_block(struct symtable *st, void *ast)
{
Py_ssize_t
end
;
Py_
DECREF
(
st
->
st_cur
);
Py_
CLEAR
(
st
->
st_cur
);
end
=
PyList_GET_SIZE
(
st
->
st_stack
)
-
1
;
if
(
end
>=
0
)
{
st
->
st_cur
=
(
PySTEntryObject
*
)
PyList_GET_ITEM
(
st
->
st_stack
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment