Added warning about uninitialized memory. #29

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet
2 participants
@chrisdew
Contributor

chrisdew commented Jan 29, 2013

Added warning about uninitialized memory. The example code does not make it clear that the "options" variable must be initialized to zero before use.

This helped me write a bug which took a few minutes to find with the help of Valgrind.

chrisdew added some commits Jan 29, 2013

Update source/processes.rst
Added note about options initialization.
@@ -31,6 +31,11 @@ exits. This is achieved using ``uv_spawn``.
:lines: 5-7,13-
:emphasize-lines: 11,13-17
+Note: ``options``, being a global variable, is implicitly initialized with

This comment has been minimized.

@nikhilm

nikhilm Feb 13, 2013

Owner

Please use reStructuredText NOTE syntax

.. NOTE::

    note text follows
@nikhilm

nikhilm Feb 13, 2013

Owner

Please use reStructuredText NOTE syntax

.. NOTE::

    note text follows
@@ -31,6 +31,11 @@ exits. This is achieved using ``uv_spawn``.
:lines: 5-7,13-
:emphasize-lines: 11,13-17
+Note: ``options``, being a global variable, is implicitly initialized with
+zeros. If you change ``options`` to a local variable, memory corruption
+will follow (thanks Valgrind for saving me a few hours!). You can use

This comment has been minimized.

@nikhilm

nikhilm Feb 13, 2013

Owner

remove parens about Valgrind :)

@nikhilm

nikhilm Feb 13, 2013

Owner

remove parens about Valgrind :)

+zeros. If you change ``options`` to a local variable, memory corruption
+will follow (thanks Valgrind for saving me a few hours!). You can use
+``memset`` to initialize a local variable of type ``uv_process_options_t``.
+

This comment has been minimized.

@nikhilm

nikhilm Feb 13, 2013

Owner

Rather than having this note, can you just change spawn/main.c itself to make options local to main and use

uv_process_options_t options = {0};

syntax instead of memset.

Thanks!

@nikhilm

nikhilm Feb 13, 2013

Owner

Rather than having this note, can you just change spawn/main.c itself to make options local to main and use

uv_process_options_t options = {0};

syntax instead of memset.

Thanks!

@nikhilm nikhilm closed this in e8a5efe Apr 3, 2013

nikhilm added a commit that referenced this pull request Apr 3, 2013

Generated gh-pages for commit e8a5efe (origin/master, master)
Author: Chris Dew <cmsdew@gmail.com>

    Added note about options initialization. Fixes #29.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment