Hi Manigandan,
Valgrind is a magic tool, and I'm always happy to introduce people to it.
Comments inline. It sounds like you figured out your problem, so all I
can add is a little commentary.
On 17/01/17 04:55 PM, Manigandan C wrote:
> Hello Graeme,
>
> Thanks for the tip. I ran Valgrind as you've suggested and found this:
>
> 1) I have a global variable "json_t * jReply"
It's probably a good idea to explicitly initialize this variable:
json_t *jReply = NULL;
> 2) Inside a function, I do "jReply = json_array ()" if certain
> conditions are satisfied. Else I leave it without initializing
> 3) In another function I am doing this,
> if (jReply != NULL) json_decref (jReply)
> 4) I get a memory error when json_decref is called with jReply not
> initialized
>
> I assumed that json_decref will set the json pointer to NULL after
> decreasing reference.
The line of code
json_decref(jReply)
can't set jReply to null -- it's a pointer passed by value, so there's
no way for the json_decref function to null it. This is a C restriction
and there's not much Jansson can do about it.
> Apparently this is not the case. Is there a way to check if the
> reference count of the json pointer is > 0 and then call json_decref?
> I did not find anything the API reference directly doing this.
As I understand it, json_decref() ignores NULL pointers, so you can call
json_decref(jReply) safely even if the pointer is already nulled. You
can see the code here:
https://github.com/akheron/jansson/blob/master/src/jansson.h#L108
...this is perhaps not a good idea, though, since it relies on the
implementation of json_decref() in a non-obvious way. Ultimately, it's
up to you whether this is a good convention or not.
cheers,
Graeme
>
> Thanks & Cheers,
> CManigandan
>
> On Tuesday, January 17, 2017 at 8:35:35 PM UTC+5:30, Graeme Smecher wrote:
>
> Hi Manigandan,
>
> Try running your application with valgrind. Otherwise there's not
> much we can do to help -- unless you can send us enough code or
> details to understand what's going on.
>
> Best,
> Graeme
>
> On Jan 17, 2017 6:45 AM, Manigandan C <
cmaniga...@gmail.com
> <javascript:>> wrote:
>
> Hi All,
>
> I am facing a memory corruption issue.
>
> My scenario:
> 1) I have written an application (let's call it App1) which
> links to jansson as dynamic library
> 2) I have a master application (let's call is App2) which forks App1
> 3) The commands to both the applications are in JSON format
> 4) Via App2 I spawn 1000 instances of App1
> 5) After a few command exchanges with App2 I get the following
> error from App2:
> *"smallbin double linked list corrupted"*
> and the application is closed with the signal
> SIGSEGV - 11 - *Invalid memory segment access*
>
>
> Any help would be much appreciated? [And it is a bit urgent ;)]
>
> Thanks in Advance,
> CManigandan
>
> --
> --
> Jansson users mailing list
>
jansso...@googlegroups.com <javascript:>
>
http://groups.google.com/group/jansson-users
> it, send an email to
jansson-user...@googlegroups.com <javascript:>.
> <
https://groups.google.com/d/optout>.
> <mailto:
jansson-user...@googlegroups.com>.