diff options
author | UbitUmarov | 2016-08-24 01:05:01 +0100 |
---|---|---|
committer | UbitUmarov | 2016-08-24 01:05:01 +0100 |
commit | 6744ec95a9a5653fff2f8ba21bfbfc8bb82c9ef5 (patch) | |
tree | 277e55baf61f40c43f72afdf865787be8f76852f | |
parent | fix a use of string Trim() (diff) | |
download | opensim-SC-6744ec95a9a5653fff2f8ba21bfbfc8bb82c9ef5.zip opensim-SC-6744ec95a9a5653fff2f8ba21bfbfc8bb82c9ef5.tar.gz opensim-SC-6744ec95a9a5653fff2f8ba21bfbfc8bb82c9ef5.tar.bz2 opensim-SC-6744ec95a9a5653fff2f8ba21bfbfc8bb82c9ef5.tar.xz |
DynamicTextureModule memory leaks
-rw-r--r-- | OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index a686a4d..665d7f7 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs | |||
@@ -553,37 +553,44 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
553 | ManagedImage managedImage; | 553 | ManagedImage managedImage; |
554 | Image image; | 554 | Image image; |
555 | 555 | ||
556 | if (OpenJPEG.DecodeToImage(frontImage, out managedImage, out image)) | 556 | if (!OpenJPEG.DecodeToImage(frontImage, out managedImage, out image) || image == null) |
557 | return null; | ||
558 | |||
559 | Bitmap image1 = new Bitmap(image); | ||
560 | image.Dispose(); | ||
561 | |||
562 | if (!OpenJPEG.DecodeToImage(backImage, out managedImage, out image) || image == null) | ||
557 | { | 563 | { |
558 | Bitmap image1 = new Bitmap(image); | 564 | image1.Dispose(); |
565 | return null; | ||
566 | } | ||
559 | 567 | ||
560 | if (OpenJPEG.DecodeToImage(backImage, out managedImage, out image)) | 568 | Bitmap image2 = new Bitmap(image); |
561 | { | 569 | image.Dispose(); |
562 | Bitmap image2 = new Bitmap(image); | ||
563 | 570 | ||
564 | if (setNewAlpha) | 571 | if (setNewAlpha) |
565 | SetAlpha(ref image1, newAlpha); | 572 | SetAlpha(ref image1, newAlpha); |
566 | 573 | ||
567 | Bitmap joint = MergeBitMaps(image1, image2); | 574 | using(Bitmap joint = MergeBitMaps(image1, image2)) |
575 | { | ||
576 | image1.Dispose(); | ||
577 | image2.Dispose(); | ||
568 | 578 | ||
569 | byte[] result = new byte[0]; | 579 | byte[] result = new byte[0]; |
570 | 580 | ||
571 | try | 581 | try |
572 | { | 582 | { |
573 | result = OpenJPEG.EncodeFromImage(joint, true); | 583 | result = OpenJPEG.EncodeFromImage(joint, true); |
574 | } | 584 | } |
575 | catch (Exception e) | 585 | catch (Exception e) |
576 | { | 586 | { |
577 | m_log.ErrorFormat( | 587 | m_log.ErrorFormat( |
578 | "[DYNAMICTEXTUREMODULE]: OpenJpeg Encode Failed. Exception {0}{1}", | 588 | "[DYNAMICTEXTUREMODULE]: OpenJpeg Encode Failed. Exception {0}{1}", |
579 | e.Message, e.StackTrace); | 589 | e.Message, e.StackTrace); |
580 | } | ||
581 | |||
582 | return result; | ||
583 | } | 590 | } |
584 | } | ||
585 | 591 | ||
586 | return null; | 592 | return result; |
593 | } | ||
587 | } | 594 | } |
588 | 595 | ||
589 | public Bitmap MergeBitMaps(Bitmap front, Bitmap back) | 596 | public Bitmap MergeBitMaps(Bitmap front, Bitmap back) |
@@ -592,12 +599,12 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture | |||
592 | Graphics jG; | 599 | Graphics jG; |
593 | 600 | ||
594 | joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb); | 601 | joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb); |
595 | jG = Graphics.FromImage(joint); | 602 | using(jG = Graphics.FromImage(joint)) |
596 | 603 | { | |
597 | jG.DrawImage(back, 0, 0, back.Width, back.Height); | 604 | jG.DrawImage(back, 0, 0, back.Width, back.Height); |
598 | jG.DrawImage(front, 0, 0, back.Width, back.Height); | 605 | jG.DrawImage(front, 0, 0, back.Width, back.Height); |
599 | 606 | return joint; | |
600 | return joint; | 607 | } |
601 | } | 608 | } |
602 | 609 | ||
603 | private void SetAlpha(ref Bitmap b, byte alpha) | 610 | private void SetAlpha(ref Bitmap b, byte alpha) |