Thread: Valgrind invalid Read/Write

  1. #1
    Registered User
    Join Date
    Nov 2016

    Post Valgrind invalid Read/Write

    Hi All,

    I would like to know how the valgrind find the runtime allocation related issues?such as the below

    invalid read of size 4.
    Invalid write of size 4.
    Even the size of memory is known at runtime,valgrind reports this

    I am asking this since i got an issue which is trying to access unknown memory and that size is declared at compile time.
    memcpy() statement throws Invalid read error.

    Thank you
    Last edited by SAP_7; 11-14-2016 at 11:50 PM. Reason: Included more details

  2. #2
    Registered User
    Join Date
    Jun 2015
    From the Valgrind documentation.
    Valgrind takes control of your program before it starts. Debugging information is read from the executable and associated libraries, so that error messages and other outputs can be phrased in terms of source code locations, when appropriate. Your program is then run on a synthetic CPU provided by the Valgrind core. As new code is executed for the first time, the core hands the code to the selected tool [i.e., Memcheck]. The tool adds its own instrumentation code to this and hands the result back to the core, which coordinates the continued execution of this instrumented code.
    The amount of instrumentation code added varies widely between tools. At one end of the scale, Memcheck adds code to check every memory access and every value computed, making it run 10-50 times slower than natively. At the other end of the spectrum, the minimal tool, called Nulgrind, adds no instrumentation at all and causes in total "only" about a 4 times slowdown.
    Valgrind simulates every single instruction your program executes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-28-2015, 02:07 PM
  2. invalid read
    By std10093 in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2014, 01:56 PM
  3. Valgrind - Invalid read of size 1
    By Castelmagno in forum C Programming
    Replies: 7
    Last Post: 02-29-2012, 03:19 PM
  4. Valgrind Invalid Read/Write In C Program
    By Alex Richman in forum C Programming
    Replies: 2
    Last Post: 10-02-2011, 03:15 PM
  5. Invalid Read from Valgrind
    By jduro in forum C Programming
    Replies: 1
    Last Post: 10-05-2010, 11:28 AM

Tags for this Thread