-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mohamedin,

On 10/8/2009 5:42 AM, Mohamedin wrote:
> I have fixed this bug (Long time without coding in C). But still the
> error.

You didn't look for all uses of "sizeof":

> while((bytes = read(inF, buff, sizeof(buff))) > 0)

I think you meant this:

while((bytes = read(inF, buff, 1024)) > 0)  // use any window size

Also, as Konstantin points out, you have a "free" in there somewhere, so
you ought to have a "malloc", too. The API documentation for
MagickGetException does not seem to indicate that the returned object
needs to be freed.

It looks like you have memory leaks everywhere. For instance:

> int resize(const char * srcFile, const char * dstFile, int width, int
> height, int quality){
> 
> char *description;
> ExceptionType severity;
> MagickWand *magick_wand;
> unsigned int status;
> 
> magick_wand = NewMagickWand();
> 
> status = MagickReadImage(magick_wand, srcFile);
> 
> if (status == False) {
> 
> ThrowAPIException(magick_wand);
> 
> return False;
> }

What about the magick_wand variable? Shouldn't you free that guy?

> MagickResizeImage(magick_wand,width,height,LanczosFilter,1.0);
> 
> MagickSetCompressionQuality(magick_wand, quality);
> 
> status=MagickWriteImages(magick_wand, dstFile,True);
> 
> if (status == False){
> 
> ThrowAPIException(magick_wand);
> 
> return False;
> }

What about freeing the memory allocated by MagickReadImage, here? You
ought to call this method before every 'return' from your function:

> DestroyMagickWand(magick_wand);

I would highly recommend that you have some with some more C experience
read-through your code. It's clear that your code is untrustworthy when
it comes to memory being managed by the JVM, and you can really ruin the
JVM's day, as you have seen.

> int resize_with_limits(const char * srcFile, const char * dstFile, int
> maxDim, int maxSize){

This function has the same problems as above.

> int crop(const char * srcFile, const char * dstFile, int widthRatio, int
> heightRatio){

Same here.

> int compose(const char * composeImgFile, const char * imageFile, int
> position, int width, int height, int shiftDirection, int shiftAmount){

Guess what? This one is correct!

> status = MagickReadImage(composite_wand, composeImgFile);
> 
> if (status == False) {
> 
> ThrowAPIException(composite_wand);
> 
> DestroyMagickWand(magick_wand);
> 
> return False;
> 
> }

The above code is the way to do things.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrOdLcACgkQ9CaO5/Lv0PD3tgCgjmH9/+G+9FIyhwJiApknBWQ2
wbgAnjmuh9Fb8xuAMIsQAUNU9Xm40HYz
=dbmW
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to